背景
pyqt5 qchart实现的动态曲线中加入鼠标的十字标签显示问题
资料
- 查找过matplotlib的鼠标十字显示,但没有找到动态曲线相关的资料,所以放弃
- 继续查找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