【问题标题】:How to make a label inside a PlotWidget?如何在 PlotWidget 内制作标签?
【发布时间】: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。我似乎无法将LabelItemTextItem 添加到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

标签: python qt pyqt pyqtgraph


【解决方案1】:

虽然现在回答这个问题有点晚了,但我会给出我的答案以防其他人需要它。

您必须更改 QTdesigner 生成的源文件。 找到创建 plotwidget 并将标题嵌入其中的行。 self.plot = PlotWidget(title= "something")

【讨论】:

    猜你喜欢
    • 2021-02-25
    • 2021-12-04
    • 1970-01-01
    • 2013-01-12
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 2019-09-27
    相关资源
    最近更新 更多