简体   繁体   中英

How to enable macOS dark mode on PyQt 5.12.2?

For example, this page claims that the newest version of PyQt5 should give me automatic dark mode for macOS Mojave, without changing a single thing on my end... Except that it doesn't.

Consider this simple example (can be copy-pasted into terminal):

exec("""\nfrom PyQt5 import QtCore, QtWidgets\n\nclass Ui_MainWindow(object):\n    def setupUi(self, MainWindow):\n        MainWindow.setObjectName("MainWindow")\n        MainWindow.resize(674, 371)\n        self.centralwidget = QtWidgets.QWidget(MainWindow)\n        self.centralwidget.setObjectName("centralwidget")\n        self.gridLayoutWidget = QtWidgets.QWidget(self.centralwidget)\n        self.gridLayoutWidget.setGeometry(QtCore.QRect(50, 10, 601, 281))\n        self.gridLayoutWidget.setObjectName("gridLayoutWidget")\n        self.mpl_layoutBox = QtWidgets.QGridLayout(self.gridLayoutWidget)\n        self.mpl_layoutBox.setContentsMargins(0, 0, 0, 0)\n        self.mpl_layoutBox.setObjectName("mpl_layoutBox")\n        self.pushButton = QtWidgets.QPushButton(self.centralwidget)\n        self.pushButton.setGeometry(QtCore.QRect(280, 300, 113, 32))\n        self.pushButton.setObjectName("pushButton")\n        MainWindow.setCentralWidget(self.centralwidget)\n\n        self.retranslateUi(MainWindow)\n        QtCore.QMetaObject.connectSlotsByName(MainWindow)\n\n    def retranslateUi(self, MainWindow):\n        _translate = QtCore.QCoreApplication.translate\n        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))\n        self.pushButton.setText(_translate("MainWindow", "PushButton"))\n\nif __name__ == "__main__":\n    import sys\n\n    app = QtWidgets.QApplication(sys.argv)\n    MainWindow = QtWidgets.QMainWindow()\n    ui = Ui_MainWindow()\n    ui.setupUi(MainWindow)\n    MainWindow.show()\n    sys.exit(app.exec_())\n""")

What must I do to enable dark mode?

好的,所以我不清楚它必须首先编译成.app,然后NSRequiresAquaSystemAppearance应该被添加到顶级Info.plist ,但是修复了它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM