src/eric7/EricWidgets/EricClickableLabel.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
12 12
13 13
14 class EricClickableLabel(QLabel): 14 class EricClickableLabel(QLabel):
15 """ 15 """
16 Class implementing a clickable label. 16 Class implementing a clickable label.
17 17
18 @signal clicked(QPoint) emitted upon a click on the label 18 @signal clicked(QPoint) emitted upon a click on the label
19 with the left button 19 with the left button
20 @signal middleClicked(QPoint) emitted upon a click on the label 20 @signal middleClicked(QPoint) emitted upon a click on the label
21 with the middle button or CTRL and left button 21 with the middle button or CTRL and left button
22 """ 22 """
23
23 clicked = pyqtSignal(QPoint) 24 clicked = pyqtSignal(QPoint)
24 middleClicked = pyqtSignal(QPoint) 25 middleClicked = pyqtSignal(QPoint)
25 26
26 def __init__(self, parent=None): 27 def __init__(self, parent=None):
27 """ 28 """
28 Constructor 29 Constructor
29 30
30 @param parent reference to the parent widget (QWidget) 31 @param parent reference to the parent widget (QWidget)
31 """ 32 """
32 super().__init__(parent) 33 super().__init__(parent)
33 34
34 self.setCursor(Qt.CursorShape.PointingHandCursor) 35 self.setCursor(Qt.CursorShape.PointingHandCursor)
35 36
36 def mouseReleaseEvent(self, evt): 37 def mouseReleaseEvent(self, evt):
37 """ 38 """
38 Protected method handling mouse release events. 39 Protected method handling mouse release events.
39 40
40 @param evt mouse event (QMouseEvent) 41 @param evt mouse event (QMouseEvent)
41 """ 42 """
42 if ( 43 if evt.button() == Qt.MouseButton.LeftButton and self.rect().contains(
43 evt.button() == Qt.MouseButton.LeftButton and 44 evt.position().toPoint()
44 self.rect().contains(evt.position().toPoint())
45 ): 45 ):
46 if evt.modifiers() == Qt.KeyboardModifier.ControlModifier: 46 if evt.modifiers() == Qt.KeyboardModifier.ControlModifier:
47 self.middleClicked.emit(evt.globalPosition().toPoint()) 47 self.middleClicked.emit(evt.globalPosition().toPoint())
48 else: 48 else:
49 self.clicked.emit(evt.globalPosition().toPoint()) 49 self.clicked.emit(evt.globalPosition().toPoint())
50 elif ( 50 elif evt.button() == Qt.MouseButton.MiddleButton and self.rect().contains(
51 evt.button() == Qt.MouseButton.MiddleButton and 51 evt.position().toPoint()
52 self.rect().contains(evt.position().toPoint())
53 ): 52 ):
54 self.middleClicked.emit(evt.globalPosition().toPoint()) 53 self.middleClicked.emit(evt.globalPosition().toPoint())
55 else: 54 else:
56 super().mouseReleaseEvent(evt) 55 super().mouseReleaseEvent(evt)

eric ide

mercurial