I am writing a class for a button and I ran into the problem that when the isDown () method gives True, then my function is called 2 times, although this is not planned. For example, here is a piece of code:
def on_hover(self): print('on_hover') pix = self.pixmap_hover return pix def on_clicked(self): print('on_clicked') pix = self.pixmap_pressed return pix def default(self): print('default') pix = self.pixmap return pix def paintEvent(self, event): pix = self.on_hover() if self.underMouse() else self.default() if self.isDown(): pix = self.on_clicked() When the cursor is not hovering over the button, it is written default
When the cursor is over the button, it is written on_hover
When the button is pressed (and held), it is written:
on_hover on_clicked on_hover on_clicked That is, the on_clicked() function is called twice
After releasing the button, it is written:
on_hover on_hover