pyqt5 qchart曲线鼠标显示

本文介绍了在使用PyQt5的QChart模块绘制动态曲线时,如何添加鼠标十字标签显示的功能。作者在尝试过程中遇到由于API变动导致的问题,并分享了从2017年的demo中获取灵感,最终修复代码的过程。
摘要由CSDN通过智能技术生成

背景

pyqt5 qchart实现的动态曲线中加入鼠标的十字标签显示问题

资料

  1. 查找过matplotlib的鼠标十字显示,但没有找到动态曲线相关的资料,所以放弃
  2. 继续查找Qchart相关资料,https://github.com/PyQt5/PyQt/blob/master/QtChart/ToolTip2.py 这个demo完美的显示,虽然是静态的曲线,但至少已找到方案,直接copy

掉坑

拉去代码后,demo时间停留在2017年,接口api已经变动了好几版,只能自己调试修改

版本

 

修复代码

from PyQt5.QtChart import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import QApplication, QGraphicsProxyWidget, QLabel, QWidget, QHBoxLayout, QVBoxLayout, QToolTip, \
    QGraphicsLineItem
import sys


class ToolTipItem(QWidget):
    def __init__(self, color, text, parent=None):
        super(ToolTipItem, self).__init__(parent)
        layout = QHBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        clabel = QLabel(self)
        clabel.setMinimumSize(12, 12)
        clabel.setMaximumSize(12, 12)
        clabel.setStyleSheet('border-radius:6px;background: rgba(%s,%s,%s,%s);' % (
            color.red(), co
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

粥截轮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值