How can I call the self.task() method without using the QTimer.singleShot(0, self.task) ? If in __init__ easy to call self.task() then the taskbarProgress will not be shown, since self.taskbarButton.setWindow(self.windowHandle()) must be called outside the constructor. It is possible after mainWindow.show() add the line mainWindow.task() , but I would like to do it inside the class, regardless of external code, if I may say so.
class MainWindow(QMainWindow, QWidget, QApplication): def __init__(self, parent = None): super(MainWindow, self).__init__(parent) QTimer.singleShot(0, self.task) # self.task() def task(self): self.taskbarButton = QWinTaskbarButton(self) self.taskbarButton.setWindow(self.windowHandle()) self.taskbarProgress = self.taskbarButton.progress() self.taskbarProgress.setRange(0, 100) self.taskbarProgress.setVisible(True) self.taskbarProgress.setValue(random.randint(0, 100)) self.taskbarProgress.show() if __name__ == '__main__': app = QApplication(sys.argv) mainWindow = MainWindow() mainWindow.show() sys.exit(app.exec_()) Update
Why do you need to inherit from the three classes?
Thanks for the comment, I will consider.
It is strange that outside the constructor is not called.
On the contrary, self.taskbarButton.setWindow(self.windowHandle()) will work correctly if called outside of the constructor (in another method) (found this information in English SO), the solution is to put it into the method, and call this method in the constructor ( judging by the examples of Qt docs in C ++, this works), but if you do this in Python ( # self.task() ), then all the same self.taskbarButton.setWindow(self.windowHandle()) does not work. (A little confusingly explained, but I do not know how clearer)
then override the
showmethod
If you use def showEvent(self, e)... , it will work every time the window is def showEvent(self, e)... .
I tried to do a redefinition:
def show(self): self.setVisible(True) self.task() It works, but is it much better than QTimer.singleShot(0, self.task) ?
Можно после mainWindow.show() дописать строку mainWindow.task()then redefine theshowmethod and call thetaskin it. - gil9redQApplicationfromQApplication, as well as inheriting fromQMainWindow, QWidgetat the same time, becauseQMainWindowitself is inherited fromQWidget- gil9redQTimer.singleShot(0, self.task)- gil9red