qt 中ui.pushButton可以实现继承么
时间: 2024-05-17 10:13:04 浏览: 141
在Qt中,ui.pushButton是一个对象而不是一个类,因此无法继承它。但是,你可以通过继承QPushButton类来创建自定义的PushButton控件类,从而实现一些定制化的功能或者样式。在Qt的UI设计器中,你可以通过向Widget添加PushButton控件来创建一个QPushButton对象,并在代码中通过访问该对象来控制它的行为。但是如果你想要添加一些额外的功能或者自定义样式的话,就需要创建自定义的控件类并继承QPushButton类了。
相关问题
from PyQt5 import QtCore, QtGui, QtWidgets from show1 import Ui_Form1 from show2 import Ui_Form2 from show3 import Ui_Form3 class Ui_Form(object): def setupUi(self, Form): Form.setObjectName("Form") Form.resize(400, 300) self.pushButton = QtWidgets.QPushButton(Form) self.pushButton.setGeometry(QtCore.QRect(90, 60, 191, 51)) font = QtGui.QFont() font.setPointSize(9) self.pushButton.setFont(font) self.pushButton.setObjectName("pushButton") self.pushButton_2 = QtWidgets.QPushButton(Form) self.pushButton_2.setGeometry(QtCore.QRect(90, 110, 191, 51)) self.pushButton_2.setObjectName("pushButton_2") self.pushButton_3 = QtWidgets.QPushButton(Form) self.pushButton_3.setGeometry(QtCore.QRect(90, 160, 191, 51)) self.pushButton_3.setObjectName("pushButton_3") self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form): _translate = QtCore.QCoreApplication.translate Form.setWindowTitle(_translate("Form", "Form")) self.pushButton.setText(_translate("Form", "无人机群显示")) self.pushButton_2.setText(_translate("Form", "无人机群数据分析展示")) self.pushButton_3.setText(_translate("Form", "无人机群飞行轨迹展示")) class MainWindow(QtWidgets.QMainWindow): def __init__(self): super().__init__() self.ui = Ui_Form() self.ui.setupUi(self) self.ui.pushButton.clicked.connect(self.showForm1) self.ui.pushButton_2.clicked.connect(self.showForm2) self.ui.pushButton_3.clicked.connect(self.showForm3) def showForm1(self): self.form1 = QtWidgets.QWidget() self.ui1 = Ui_Form1() self.ui1.setupUi(self.form1) self.form1.show() def showForm2(self): self.form2 = QtWidgets.QWidget() self.ui2 = Ui_Form2() self.ui2.setupUi(self.form2) self.form2.show() def showForm3(self): self.form3 = QtWidgets.QWidget() self.ui3 = Ui
_Form3() self.ui3.setupUi(self.form3) self.form3.show()
这段代码是一个基于PyQt5的GUI程序,它创建了一个主窗口并在窗口中添加了三个按钮。当用户单击按钮时,程序会打开另外三个窗口,分别用于显示无人机群的位置、数据分析和飞行轨迹。这个程序的核心是MainWindow类,它继承自QtWidgets.QMainWindow,并在__init__方法中创建了UI对象并连接了三个按钮的clicked信号到对应的槽函数showForm1、showForm2和showForm3。这三个槽函数分别创建了对应的窗口对象,并在窗口中添加了对应的UI组件,并将窗口显示出来。
class mywindow(QtWidgets.QMainWindow,Ui_MainWindow): switch_window1 = QtCore.pyqtSignal() # 跳转信号 switch_window2 = QtCore.pyqtSignal(str) # 跳转信号 switch_window3 = QtCore.pyqtSignal(str) # 跳转信号 switch_window4 = QtCore.pyqtSignal() # 跳转信号 def __init__(self): super(mywindow,self).__init__() self.setupUi(self) self.retranslateUi(self) self.pushButton.clicked.connect(self.goRank) self.pushButton_3.clicked.connect(self.goCar) self.pushButton_2.clicked.connect(self.goCompare) self.pushButton_4.clicked.connect(self.goMarket) def goRank(self): self.switch_window1.emit() def goCar(self): self.switch_window2.emit("") def goCompare(self): self.switch_window3.emit("") def goMarket(self): self.switch_window4.emit()他是不是继承了ui——window
是的,这段代码中的 `class mywindow(QtWidgets.QMainWindow,Ui_MainWindow)` 继承了 `QtWidgets.QMainWindow` 和 `Ui_MainWindow` 两个类,其中 `Ui_MainWindow` 可能是通过 Qt Designer 工具生成的界面类。继承了 `Ui_MainWindow` 后,可以使用该类中定义的界面控件。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)