1. <tfoot id='6gRUQ'></tfoot>

      <legend id='6gRUQ'><style id='6gRUQ'><dir id='6gRUQ'><q id='6gRUQ'></q></dir></style></legend>
    1. <i id='6gRUQ'><tr id='6gRUQ'><dt id='6gRUQ'><q id='6gRUQ'><span id='6gRUQ'><b id='6gRUQ'><form id='6gRUQ'><ins id='6gRUQ'></ins><ul id='6gRUQ'></ul><sub id='6gRUQ'></sub></form><legend id='6gRUQ'></legend><bdo id='6gRUQ'><pre id='6gRUQ'><center id='6gRUQ'></center></pre></bdo></b><th id='6gRUQ'></th></span></q></dt></tr></i><div id='6gRUQ'><tfoot id='6gRUQ'></tfoot><dl id='6gRUQ'><fieldset id='6gRUQ'></fieldset></dl></div>

      • <bdo id='6gRUQ'></bdo><ul id='6gRUQ'></ul>

      <small id='6gRUQ'></small><noframes id='6gRUQ'>

      pyQt5 更改 MainWindow 标志

      时间:2023-08-04
        • <bdo id='j7Y4G'></bdo><ul id='j7Y4G'></ul>

            <tbody id='j7Y4G'></tbody>
          1. <tfoot id='j7Y4G'></tfoot>
          2. <i id='j7Y4G'><tr id='j7Y4G'><dt id='j7Y4G'><q id='j7Y4G'><span id='j7Y4G'><b id='j7Y4G'><form id='j7Y4G'><ins id='j7Y4G'></ins><ul id='j7Y4G'></ul><sub id='j7Y4G'></sub></form><legend id='j7Y4G'></legend><bdo id='j7Y4G'><pre id='j7Y4G'><center id='j7Y4G'></center></pre></bdo></b><th id='j7Y4G'></th></span></q></dt></tr></i><div id='j7Y4G'><tfoot id='j7Y4G'></tfoot><dl id='j7Y4G'><fieldset id='j7Y4G'></fieldset></dl></div>
            <legend id='j7Y4G'><style id='j7Y4G'><dir id='j7Y4G'><q id='j7Y4G'></q></dir></style></legend>

            <small id='j7Y4G'></small><noframes id='j7Y4G'>

                本文介绍了pyQt5 更改 MainWindow 标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我使用 python 3.4、pyQt5 和 Qt 设计器(Winpython 发行版).我喜欢由设计师制作 gui 并使用 setupUi 将它们导入 python 的想法.我能够显示 MainWindows 和 QDialogs.但是,现在我想设置我的 MainWindow,总是在顶部并且只有关闭按钮.我知道这可以通过设置 Windows 标志来完成.我尝试执行以下操作:

                I use python 3.4 , pyQt5 and Qt designer (Winpython distribution). I like the idea of making guis by designer and importing them in python with setupUi. I'm able to show MainWindows and QDialogs. However, now I would like to set my MainWindow, always on top and with the close button only. I know this can be done by setting Windows flags. I tried to do as following:

                from PyQt5 import QtCore, QtGui, QtWidgets
                import sys
                class MainWindow(QtWidgets.QMainWindow,Ui_MainWindow):
                    def __init__(self, parent=None):
                        super(MainWindow, self).__init__(parent)
                        self.setupUi(self)
                        self.setWindowFlags(QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.WindowMinimizeButtonHint)
                        self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
                if __name__ == '__main__':
                    app = QtWidgets.QApplication(sys.argv)
                    form = MainWindow()
                    form.show()
                    sys.exit(app.exec_())
                

                显示主窗口(没有错误),但未应用标志.我想这是因为我在创建 Windows 属性后要求更改它.现在,问题是:我如何在不直接修改 Ui_MainWindow 的情况下做到这一点?可以在 Qt 设计器中更改标志吗?谢谢

                The MainWindow shows up (without error) but Flags are not applied. I suppose this is because I asked to change Windows properties after it was already created. Now, questions are : how I can do it without modify Ui_MainWindow directly? It is possible to change flags in Qt designer ? Thanks

                推荐答案

                每次调用 setWindowFlags 都会完全覆盖当前设置,因此您需要一次设置所有标志.此外,您必须包含 CustomizeWindowHint 标志,否则所有其他提示将被忽略.以下可能适用于 Windows:

                Every call of setWindowFlags will completely override the current settings, so you need to set all the flags at once. Also, you must include the CustomizeWindowHint flag, otherwise all the other hints will be ignored. The following will probably work on Windows:

                    self.setWindowFlags(
                        QtCore.Qt.Window |
                        QtCore.Qt.CustomizeWindowHint |
                        QtCore.Qt.WindowTitleHint |
                        QtCore.Qt.WindowCloseButtonHint |
                        QtCore.Qt.WindowStaysOnTopHint
                        )
                

                但是,这不太可能适用于所有平台.提示"确实就是这个意思.窗口管理器完全可以忽略这些标志,并且不能保证它们都会以相同的方式运行.

                However, it is highly unlikely this will work on all platforms. "Hint" really does mean just that. Window managers are completely free to ignore these flags and there's no guarantee they will all behave in the same way.

                PS:

                不能在 Qt Designer 中设置窗口标志.

                It is not possible to set the window flags in Qt Designer.

                这篇关于pyQt5 更改 MainWindow 标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Pycharm、PyQt5 和 Python 2.7——没有代码完成 下一篇:PyQt5 - 如何从工作线程发出信号以通过 GUI 线程调

                相关文章

                最新文章

                  <bdo id='S45KC'></bdo><ul id='S45KC'></ul>
                <i id='S45KC'><tr id='S45KC'><dt id='S45KC'><q id='S45KC'><span id='S45KC'><b id='S45KC'><form id='S45KC'><ins id='S45KC'></ins><ul id='S45KC'></ul><sub id='S45KC'></sub></form><legend id='S45KC'></legend><bdo id='S45KC'><pre id='S45KC'><center id='S45KC'></center></pre></bdo></b><th id='S45KC'></th></span></q></dt></tr></i><div id='S45KC'><tfoot id='S45KC'></tfoot><dl id='S45KC'><fieldset id='S45KC'></fieldset></dl></div>

                    <small id='S45KC'></small><noframes id='S45KC'>

                    <legend id='S45KC'><style id='S45KC'><dir id='S45KC'><q id='S45KC'></q></dir></style></legend>
                    <tfoot id='S45KC'></tfoot>