Unsolved Why my QPushButtons are disable on Mac OS X whereas they are enable on Windows?
-
Environment:
Windows 10
Mac OS X Mojave 10.14.6
Python 3.7
Pyqt5
Problem:
I am developping a software with Python. I am loading a UI with 'uic.loadUi'. Before to show all the buttons and labels, my program need to run some preparation tasks in a Qthread and show a loading gif while this preparation is working.
Then it shows all the buttons and labels.
To handle the displays of all the elements, I am using a JSON file which I update. It is useful to bulk change attributs of all element, and also it is not disturbing the Qthread when I want to change element.
I made the method "DisplayFields()" which load the new attributs of elements.
My problem is all my buttons are disable (blocked, I can't click on it) when I run my program on Mac OS X whereas they are all enable and working when I run my program on Windows 10.
here is the code:
class Ui(QtWidgets.QMainWindow): def __init__(self): global number_connected_phones super(Ui, self).__init__() uic.loadUi('ui/MyAppUI.Ui', self) # === We display the UI ========== self.show() self.DisplayFields() def DisplayFields(self): with open('ui/ui.json') as fjson: data_fields = json.load(fjson) fjson.close() for button_element in data_fields['buttons']: self.findChild(QPushButton, button_element['name']).setText(button_element['value']) self.findChild(QPushButton, button_element['name']).setStyleSheet(f"color: {button_element['color']}") self.findChild(QPushButton, button_element['name']).setStyleSheet( f"background-color: {button_element['background-color']}") self.findChild(QPushButton, button_element['name']).setEnabled(button_element['enable']) if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) window = Ui() app.exec_()
Here is the UI which you need to load with uic.loadUi:
https://www.learnpyqt.com/courses/concurrent-execution/multithreading-pyqt-applications-qthreadpool/
here is the Json file:
https://drive.google.com/file/d/1TlAPW6GgjTQ-WvfmPKCvXw3RLv_iT_oo/view?usp=sharing
Does anyone already faced this kind of issue with Mac OS X?
-
Hi,
What version of PyQt are you using ?
I vaguely remember some issues related to stylesheets (please check the bug report system).Try removing them to see if it changes the situation.
-
Hi,
Thanks for helping me.
I use the PyQt5 5.15.0
Your bug report link give me error message: DNS_PROBE_FINISHED_NXDOMAIN
-
Sorry ! Linked fix
-
@SGaist said in Why my QPushButtons are disable on Mac OS X whereas they are enable on Windows?:
stylesheets
Thank you.
I had a look and may have found some bugs corresponding to mine.
But many of them don't concern the 5.15.0 version
And even if I found one for the 5.15.0, I didn't see where was the solution.I am so sorry to bother you, I am a newbie, Could you guide me to the solution, please?
-
Did you try the stylesheet removal I suggested ?
-
Yes it works without the stylesheet. Thank you so much for your help.
But now I have another problem. I can't change the color of my buttons. DO you have any idea how long it will take to fix this bug?
-
In fact the bug is not only for setstylesheet, but also for setEnabled.
Obviously, on MAC OS X, QT5 can't change the attributes of buttons.You can reproduce the bug with the code I published here.
I hope you could fix this issue soon.
Thanks again for your help.
-
Hi @CentreFF
There is a similar bug in Pyside 2 (Qt for Python) in the default macOS style plugin: https://bugreports.qt.io/browse/PYSIDE-695
The workaround in the report was to call
app.setStyle('Fusion')
in__main__
before you construct your window. Could you please test to see if it works for you? -
This is a regression bug in Qt 5.15.0. The next release will be fine. That means that the easiest solution to your problem is to use an earlier version of Qt (I personally did go back to 5.13.2 as this is the version we are using on other platforms anyway). This solution has worked well for us.
-
@SimonSchroeder said in Why my QPushButtons are disable on Mac OS X whereas they are enable on Windows?:
This is a regression bug in Qt 5.15.0. The next release will be fine. That means that the easiest solution to your problem is to use an earlier version of Qt (I personally did go back to 5.13.2 as this is the version we are using on other platforms anyway). This solution has worked well for us.
Thanks, @SimonSchroeder. Do you have a link to the regression report or the fix?
-
https://bugreports.qt.io/browse/QTBUG-85487
It says that it is closed and fix version is 5.15.1.