python - Qt中两个MainWindow()之间的通信

标签 python c++ qt pyqt

我在 Qt 中的应用程序包含 2 个不同的窗口(但都继承自 QtGui.QMainWIndow),我想知道如何在它们之间进行通信。此外,使用多个 QMainWindow 通常是一种好方法吗?

最佳答案

在实例化两个窗口类时连接它们之间的信号和槽。

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 设计用作主应用程序窗口;它简化了工具栏和菜单等常用窗口功能的添加。但是,我认为拥有多个实例没有任何害处。

您也可以只使用任何QWidget:

window = QtWidgets.QWidget()    # note that no parent is given
window.show()

关于python - Qt中两个MainWindow()之间的通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35041711/

相关文章:

python - 如何将欧元货币字符串转换为 float ?

c++ - 使用 UDP 协议(protocol)发送结构并写入数据报

css - 在 QTreeView 中为不同的复选框设置不同的图像

c++ - 有没有办法设置 QPicture 的 DPI?

python - 使用公共(public) GPS 数据计算速度

python - 检查python中networkx中是否存在具有相同标签的节点

python - 多维度的 Numpy 花式索引

c++ boost 库 - 写入 ini 文件而不覆盖?

c++ - 为什么在使用 OpenGL 核心配置文件时会崩溃?

c++ - 错误 C2679 : binary '>' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)