简体   繁体   English

使用 PyQt 在 Qt 设计器 GUI 上嵌入实时 2D 热图

[英]Embedding a live 2D heatmap on a Qt designer GUI using PyQt

I am trying to embed a live 8x8 heatmap on a Qt designer based GUI.我正在尝试在基于 Qt 设计器的 GUI 上嵌入实时 8x8 热图。 The heatmap is supposed to refresh at ~30Hz.热图应该以 ~30Hz 刷新。 I have created a widget on the GUI window and promoted it to a 'Heatmap' class that I created in a python file.我在 GUI 窗口上创建了一个小部件,并将其提升为我在 python 文件中创建的“热图”类。

Based on the research I have done online, pyqtgraph seems like something I could use for this.根据我在网上所做的研究, pyqtgraph似乎是我可以使用的东西。 I am trying to inherit the Heatmap class from the pyqtgraph.ImageItem class but getting an error when running the GUI.我想继承Heatmap从类pyqtgraph.ImageItem类,但在运行GUI时得到一个错误。 Here's how the Qt designer output file (created from the .ui file) is creating an instance of the Heatmap class:以下是 Qt 设计器输出文件(从 .ui 文件创建)如何创建Heatmap类的实例:

self.heatmap = Heatmap(self.verticalLayoutWidget_2)

where verticalLayoutWidget_2 is a vertical layout widget I created on the GUI window.其中verticalLayoutWidget_2是我在 GUI 窗口上创建的垂直布局小部件。

But it gives the following error:但它给出了以下错误:

TypeError: addWidget(self, QWidget, stretch: int = 0, alignment: Union[Qt.Alignment, Qt.AlignmentFlag] = 0): argument 1 has unexpected type 'Heatmap'类型错误:addWidget(self,QWidget,stretch:int = 0,alignment:Union[Qt.Alignment,Qt.AlignmentFlag] = 0):参数1具有意外类型“热图”

I am not sure if the packages I am trying to use are the best or even the correct ones for creating the live heatmap.我不确定我尝试使用的软件包是否是用于创建实时热图的最佳软件包,甚至是正确的软件包。 I'd appreciate any help that would point me in the right direction.我会很感激任何能帮我指明正确方向的帮助。 I am new to python based GUI development so please bear with me.我是基于 python 的 GUI 开发的新手,所以请耐心等待。

If you are inheriting from ImageItem, your heatmap does not inherit from QWidget, which is the required input to addWidget.如果您从 ImageItem 继承,则您的热图不会从 QWidget 继承,而 QWidget 是 addWidget 所需的输入。 Try inheriting from ImageView, which inherits directly from QWidget.尝试从 ImageView 继承,它直接从 QWidget 继承。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM