Advertisement
Joss13

mouse click event prob

Jan 29th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. import sys, os
  2.  
  3. import Qt
  4. from Qt.QtCore import *
  5. from Qt.QtGui import *
  6. from Qt.QtWidgets import *
  7.  
  8.  
  9. class RButton(QPushButton):
  10.     """
  11.     """
  12.     rclicked = Signal()
  13.  
  14.     def __init__(self, parent=None, name='Button'):
  15.         """
  16.         """
  17.         super(RButton, self).__init__(parent=parent)
  18.         self.setText(name)
  19.  
  20.  
  21.     def mousePressEvent(self, e):
  22.         if e.type() == QEvent.MouseButtonPress:
  23.             if e.button() == Qt.RightButton:
  24.                 self.rclicked.emit()
  25.                 e.accept()
  26.             else:
  27.                 super(QPushButton, self).mousePressEvent(e)
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. def clicked():
  37.     print('clicked')
  38. def rclicked():
  39.     print('rclicked')
  40.  
  41. def show():
  42.     app = QApplication(sys.argv)
  43.     win = QWidget(None)
  44.     lay = QVBoxLayout(win)
  45.     #
  46.     b = RButton(win, 'Derived')
  47.     lay.addWidget(b)
  48.     b.clicked.connect(clicked)
  49.     b.rclicked.connect(rclicked)
  50.     #
  51.     b2 = QPushButton(win)
  52.     b2.setText('QPushButton')
  53.     lay.addWidget(b2)
  54.     b2.clicked.connect(clicked)
  55.     #
  56.     win.show()
  57.     app.exec_()
  58.  
  59.  
  60. if __name__ == "__main__":
  61.     show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement