Python - PyQt5 Fejl Med Mac Kompatibilitet

Indlæg af Hanne Mølgaard Plasc

Problem



Jeg har for nylig skrevet en applikation med en PyQt5 brugergrænseflade, og programmet fungerer perfekt på windows. Men ved at køre på en Mac, vises brugergrænsefladen, men er ikke længere interaktiv; Ingen af ​​knapperne eller indtastningsfelterne er funktionelle, og hvert element er gråt ud. Koden er den samme og synes ikke at indeholde noget, der er specifikt for begge operativsystemer. Programmet blev skrevet og kører på Windows 10 og sprang i problemer på Mac OSX El Capitan.


Hvordan kan jeg løse dette problem?


Nedenfor er et eksempel. Følgende kode vil give et fuldt interaktivt brugergrænseflade til Windows, men et ikke-fungerende 'frosset' og gråtonet brugergrænseflade på Mac, selvom det er bygget fra bunden på Mac.


# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'test2.ui'
#
# Created by: PyQt5 UI code generator 5.10.1
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui\_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(403, 365)
        self.verticalLayoutWidget = QtWidgets.QWidget(Dialog)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(19, 9, 361, 181))
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setObjectName("verticalLayout")
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.verticalLayout\_2 = QtWidgets.QVBoxLayout()
        self.verticalLayout\_2.setObjectName("verticalLayout\_2")
        self.gridLayout = QtWidgets.QGridLayout()
        self.gridLayout.setObjectName("gridLayout")
        self.directory = QtWidgets.QLineEdit(self.verticalLayoutWidget)
        self.directory.setObjectName("directory")
        self.gridLayout.addWidget(self.directory, 5, 3, 1, 1)
        self.label\_3 = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.label\_3.setObjectName("label\_3")
        self.gridLayout.addWidget(self.label\_3, 3, 0, 1, 1)
        spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.gridLayout.addItem(spacerItem, 2, 0, 1, 1)
        self.label\_2 = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.label\_2.setObjectName("label\_2")
        self.gridLayout.addWidget(self.label\_2, 4, 0, 1, 1)
        self.label = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.label.setObjectName("label")
        self.gridLayout.addWidget(self.label, 5, 0, 1, 1)
        self.filename = QtWidgets.QLineEdit(self.verticalLayoutWidget)
        self.filename.setObjectName("filename")
        self.gridLayout.addWidget(self.filename, 4, 3, 1, 1)
        self.URL = QtWidgets.QLineEdit(self.verticalLayoutWidget)
        self.URL.setObjectName("URL")
        self.gridLayout.addWidget(self.URL, 3, 3, 1, 1)
        spacerItem1 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.gridLayout.addItem(spacerItem1, 6, 0, 1, 1)
        self.label\_4 = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.label\_4.setObjectName("label\_4")
        self.gridLayout.addWidget(self.label\_4, 2, 3, 1, 1)
        self.horizontalLayout\_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout\_3.setObjectName("horizontalLayout\_3")
        self.checkBox\_2 = QtWidgets.QCheckBox(self.verticalLayoutWidget)
        self.checkBox\_2.setObjectName("checkBox\_2")
        self.horizontalLayout\_3.addWidget(self.checkBox\_2)
        self.checkBox\_3 = QtWidgets.QCheckBox(self.verticalLayoutWidget)
        self.checkBox\_3.setObjectName("checkBox\_3")
        self.horizontalLayout\_3.addWidget(self.checkBox\_3)
        self.checkBox = QtWidgets.QCheckBox(self.verticalLayoutWidget)
        self.checkBox.setObjectName("checkBox")
        self.horizontalLayout\_3.addWidget(self.checkBox)
        self.gridLayout.addLayout(self.horizontalLayout\_3, 6, 3, 1, 1)
        self.verticalLayout\_2.addLayout(self.gridLayout)
        self.horizontalLayout.addLayout(self.verticalLayout\_2)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.verticalLayoutWidget\_3 = QtWidgets.QWidget(Dialog)
        self.verticalLayoutWidget\_3.setGeometry(QtCore.QRect(20, 190, 361, 153))
        self.verticalLayoutWidget\_3.setObjectName("verticalLayoutWidget\_3")
        self.verticalLayout\_3 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget\_3)
        self.verticalLayout\_3.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout\_3.setObjectName("verticalLayout\_3")
        self.main\_out = QtWidgets.QTextBrowser(self.verticalLayoutWidget\_3)
        self.main\_out.setObjectName("main\_out")
        self.verticalLayout\_3.addWidget(self.main\_out)
        self.progress = QtWidgets.QProgressBar(self.verticalLayoutWidget\_3)
        self.progress.setProperty("value", 24)
        self.progress.setObjectName("progress")
        self.verticalLayout\_3.addWidget(self.progress)
        self.cancel\_button = QtWidgets.QDialogButtonBox(self.verticalLayoutWidget\_3)
        self.cancel\_button.setOrientation(QtCore.Qt.Horizontal)
        self.cancel\_button.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
        self.cancel\_button.setObjectName("cancel\_button")
        self.verticalLayout\_3.addWidget(self.cancel\_button)

        self.retranslateUi(Dialog)
        self.cancel\_button.accepted.connect(Dialog.accept)
        self.cancel\_button.rejected.connect(Dialog.reject)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        \_translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(\_translate("Dialog", "Dialog"))
        self.label\_3.setText(\_translate("Dialog", "URL:"))
        self.label\_2.setText(\_translate("Dialog", "Save As:"))
        self.label.setText(\_translate("Dialog", "Save In:"))
        self.label\_4.setText(\_translate("Dialog", "TextLabel"))
        self.checkBox\_2.setText(\_translate("Dialog", "CheckBox"))
        self.checkBox\_3.setText(\_translate("Dialog", "CheckBox"))
        self.checkBox.setText(\_translate("Dialog", "CheckBox"))

if \_\_name\_\_ == "\_\_main\_\_":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    ui = Ui\_Dialog()
    MainWindow = QtWidgets.QDialog()
    ui.setupUi(MainWindow)
    MainWindow.show()

Bedste reference