A
A
Alan Gibizov2020-05-03 16:51:20
Python
Alan Gibizov, 2020-05-03 16:51:20

PyQT5 on MACOS - why is the status bar sometimes not redrawn?

The pythonworld site has a tutorial on getting started with PyQT5.
There is an example that does not render the image correctly for me.

Example code
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
from PyQt5.QtWidgets import QMainWindow, QPushButton, QApplication


class Example(QMainWindow):

    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        btn1 = QPushButton("Button 1", self)
        btn1.move(30, 50)

        btn2 = QPushButton("Button 2", self)
        btn2.move(150, 50)

        btn1.clicked.connect(self.buttonClicked)
        btn2.clicked.connect(self.buttonClicked)

        self.statusBar()

        self.setGeometry(300, 300, 290, 150)
        self.setWindowTitle('Event sender')
        self.show()

    def buttonClicked(self):
        sender = self.sender()
        self.statusBar().showMessage(sender.text() + ' was pressed')


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

This code draws a window with two buttons, and depending on the clicked button in the status bar of the window, writes which button is pressed.
So it sometimes does not render this change (ie, the event occurred, the buttonClicked method was called, it worked, but the image on the window did not change). If you click back and forth, it can sometimes fizzle out, then it can stop drawing again. I tried to insert the print(sender.text()) line into the buttonClicked method, it works correctly.

This is, of course, just an example; but this can also occur in a real application - and it is rather difficult to understand whether the application logic does not work, or the graphics do not render. And it can, after all, work fine on some computers, but fail on others.

Is there a way to track such a glitch programmatically (probably, there are no easy ways, but suddenly)? What could be the problem - in the system video stack, in PyQT for MACOS, in the application code? How to understand exactly where?

Ps if you update the screen, for example, go to another screen, then return to this one - the picture is updated.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andy_U, 2020-05-04
@phaggi

Not your case ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question