[英]Communicate between two MainWindow() in Qt
My app, in Qt, consists in 2 different windows (but both inherited from QtGui.QMainWIndow), and I am wondering how to communicate between them. 我在Qt中的应用程序包含2个不同的窗口(但均继承自QtGui.QMainWIndow),我想知道如何在它们之间进行通信。 Moreover, does using multiple QMainWindow is generally a good approach?
此外,使用多个QMainWindow通常是否是一个好方法?
Connect signals and slots between the two window classes when you instantiate them. 实例化它们时,请在两个窗口类之间连接信号和插槽。
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
window1 = MyMainWindow1()
window1.show()
window2 = MyMainWindow2()
window2.show()
# connect signals to communicate between windows
window1.someSignal.connect(window2.someSlot)
window2.anotherSignal.connect(window1.anotherSlot)
app.exec()
QMainWindow
is designed to be used as the main application window; QMainWindow
被设计为用作主应用程序窗口。 it simplifies the addition of common window features like toolbars and menus. 它简化了常用窗口功能(如工具栏和菜单)的添加。 However, I don't think there is any harm in having multiple instances.
但是,我认为拥有多个实例不会有任何危害。
You can also just use any QWidget
: 您也可以使用任何
QWidget
:
window = QtWidgets.QWidget() # note that no parent is given
window.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.