Bottom Page

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?
Quote
#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_())
Quote
#3
Many thanks for porting the code from C++ to Python.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 299 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  QTabBar Indexing is wrong for right mouse click xenas 2 478 Jan-04-2019, 10:08 PM
Last Post: xenas
  right mouse button click with PyQt5 brecht83 4 3,397 Nov-09-2018, 02:55 PM
Last Post: brecht83
  [PyQt] QSlider jump to mouse click position MegasXLR 2 2,137 May-26-2018, 08:55 AM
Last Post: MegasXLR
  (pyQt/pySide)setStyleSheet(border…) makes QPushButton not clickable in Maya vladlenPy 0 1,488 Apr-15-2018, 12:41 PM
Last Post: vladlenPy

Forum Jump:


Users browsing this thread: 1 Guest(s)