我在用 qt 生成的 .ui 文件 tipicali 中看到你可以用你的类创建你的小部件,但是我不知道如何用参数创建一个类,然后我决定在 python 中创建。 小部件的焦点是显示一个图形,我看到你可以使用 pyqtgraph 但我不知道如何将它添加到一个类中,我看到在用 qt 生成的 .ui 文件中你可以添加一个标题到你的班级。
.ui文件中的代码:
<customwidgets>
<customwidget>
<class>PlotWidget</class>
<extends>QWidget</extends>
<header>pyqtgraph</header>
<container>1</container>
</customwidget>
</customwidgets>
我试着在网上看一些教程,但我没有找到用 Python 代码翻译它的方法。
在我的尝试中,我写了这个: `从 PyQt5.QtWidgets 导入 QWidget 从 PyQt5 导入 QtCore 将 pyqtgraph 导入为 pg
class MyGraphs(QWidget):
def __init__(self, name) -> None:
super().__init__()
self.setGeometry(10,10,271,201)
self.setObjectName(name)
self.setStyleSheet("background-color: white")
self.setVisible(True)
我不能在我的新小部件中使用命令 pyqtgraph。 也许我不知道我是否将小部件正确添加到我的 gui(使用 .ui 文件制作),因为我在屏幕上看不到 noffing
有人可以帮助我吗?非常感谢。