Python Forum
[PyQt] `QPushButton` without mouse click animation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] `QPushButton` without mouse click animation
#1
Hi

I'm looking for a way to disable the left click animation of a QPushButton, but animation and left mouse click seems to be tightly connected within Qt.

How to disable click animation for left mouse clicks?
Reply
#2
Perhaps you could use a QLabel instead and implement something similar to this: https://www.qtcentre.org/threads/20568-l...post100767

Here I translated it for you:

#!/usr/bin/python3
import sys
from PyQt5 import QtCore, QtWidgets


class ClickableLabel(QtWidgets.QLabel):
    clicked = QtCore.pyqtSignal()

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

    def mouseReleaseEvent(self, event):
        if event.button () == QtCore.Qt.LeftButton:
            self.clicked.emit()


class Main(QtWidgets.QMainWindow):
    def __init__(self, parent):
        super().__init__()
        self.ui = QtWidgets.QWidget(self)
        self.setCentralWidget(self.ui)
        self.ui.label = ClickableLabel(self)
        self.ui.label.clicked.connect(self.close)
        self.ui.label.setText("Close")
        self.ui.layout = QtWidgets.QVBoxLayout()
        self.ui.layout.addWidget(self.ui.label)
        self.ui.setLayout(self.ui.layout)
        self.show()

if __name__== '__main__':
    app = QtWidgets.QApplication(sys.argv)
    gui = Main(app)
    sys.exit(app.exec_())
Reply
#3
Many thanks for porting the code from C++ to Python.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter - touchscreen, push the button like click the mouse John64 5 739 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  [PyQt] QPushButton and and QmenuBar issues zettai 5 2,444 Oct-28-2020, 07:55 AM
Last Post: Axel_Erfurt
  [Tkinter] Mouse click without use bind ATARI_LIVE 8 7,241 Oct-23-2020, 10:41 PM
Last Post: ATARI_LIVE
  [Tkinter] program unresponsive during pynput mouse click RobotTech 1 3,431 May-07-2020, 04:43 PM
Last Post: RobotTech
  [Tkinter] Mouse click event not working on multiple tkinter window evrydaywannabe 2 3,704 Dec-16-2019, 04:47 AM
Last Post: woooee
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 4,947 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  QTabBar Indexing is wrong for right mouse click xenas 2 2,474 Jan-04-2019, 10:08 PM
Last Post: xenas
  right mouse button click with PyQt5 brecht83 4 19,291 Nov-09-2018, 02:55 PM
Last Post: brecht83
  [PyQt] QSlider jump to mouse click position MegasXLR 2 8,174 May-26-2018, 08:55 AM
Last Post: MegasXLR
  (pyQt/pySide)setStyleSheet(border…) makes QPushButton not clickable in Maya vladlenPy 0 4,694 Apr-15-2018, 12:41 PM
Last Post: vladlenPy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020