Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, os
- import Qt
- from Qt.QtCore import *
- from Qt.QtGui import *
- from Qt.QtWidgets import *
- class RButton(QPushButton):
- """
- """
- rclicked = Signal()
- def __init__(self, parent=None, name='Button'):
- """
- """
- super(RButton, self).__init__(parent=parent)
- self.setText(name)
- def mousePressEvent(self, e):
- if e.type() == QEvent.MouseButtonPress:
- if e.button() == Qt.RightButton:
- self.rclicked.emit()
- e.accept()
- else:
- super(QPushButton, self).mousePressEvent(e)
- def clicked():
- print('clicked')
- def rclicked():
- print('rclicked')
- def show():
- app = QApplication(sys.argv)
- win = QWidget(None)
- lay = QVBoxLayout(win)
- #
- b = RButton(win, 'Derived')
- lay.addWidget(b)
- b.clicked.connect(clicked)
- b.rclicked.connect(rclicked)
- #
- b2 = QPushButton(win)
- b2.setText('QPushButton')
- lay.addWidget(b2)
- b2.clicked.connect(clicked)
- #
- win.show()
- app.exec_()
- if __name__ == "__main__":
- show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement