【发布时间】:2017-12-16 22:51:51
【问题描述】:
我正在使用 Qt 和 pyqtgraph 制作 GUI。它有几个 PlotWidgets - 这是它的一部分:
我想将鼠标光标位置(按比例单位)作为标签包含在图中,有点像 pyqtgraph 十字准线示例:
该示例通过将LabelItem 添加到GraphicsWindow 来工作,如下所示:
win = pg.GraphicsWindow()
label = pg.LabelItem(justify='right')
p1 = win.addPlot(row=1, col=0)
但我没有GraphicsWindow,只是一个普通的Qt 窗口(使用设计器构建),其中包含PlotWidgets。我似乎无法将LabelItem 或TextItem 添加到PlotWidget。我确信必须有一种“标准”方式来做到这一点,但我无法弄清楚,谷歌似乎也不知道。有什么想法吗?
编辑:这是来自窗口__init__ 函数的我的代码的sn-p:
self.B_field_plot.setLabels(title='Magnetic field', left='B [T]', bottom='z [m]')
self.label = pg.LabelItem(justify="right")
self.B_field_plot.addItem(self.label)
self.label.setText('Hello')
标签没有出现。
【问题讨论】:
-
你能告诉我你的代码吗
-
你的 plotWidget 在哪里?
-
B_field_plot 是 plotWidget?
-
这是
B_field_plot