eric7/E5Gui/E5ClickableLabel.py

branch
eric7
changeset 8356
68ec9c3d4de5
parent 8355
8a7677a63c8d
child 8357
a081458cc57b
equal deleted inserted replaced
8355:8a7677a63c8d 8356:68ec9c3d4de5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2012 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a clickable label.
8 """
9
10 from PyQt6.QtCore import pyqtSignal, Qt, QPoint
11 from PyQt6.QtWidgets import QLabel
12
13
14 class E5ClickableLabel(QLabel):
15 """
16 Class implementing a clickable label.
17
18 @signal clicked(QPoint) emitted upon a click on the label
19 with the left button
20 @signal middleClicked(QPoint) emitted upon a click on the label
21 with the middle button or CTRL and left button
22 """
23 clicked = pyqtSignal(QPoint)
24 middleClicked = pyqtSignal(QPoint)
25
26 def __init__(self, parent=None):
27 """
28 Constructor
29
30 @param parent reference to the parent widget (QWidget)
31 """
32 super().__init__(parent)
33
34 self.setCursor(Qt.CursorShape.PointingHandCursor)
35
36 def mouseReleaseEvent(self, evt):
37 """
38 Protected method handling mouse release events.
39
40 @param evt mouse event (QMouseEvent)
41 """
42 if (
43 evt.button() == Qt.MouseButton.LeftButton and
44 self.rect().contains(evt.position().toPoint())
45 ):
46 if evt.modifiers() == Qt.KeyboardModifier.ControlModifier:
47 self.middleClicked.emit(evt.globalPosition().toPoint())
48 else:
49 self.clicked.emit(evt.globalPosition().toPoint())
50 elif (
51 evt.button() == Qt.MouseButton.MiddleButton and
52 self.rect().contains(evt.position().toPoint())
53 ):
54 self.middleClicked.emit(evt.globalPosition().toPoint())
55 else:
56 super().mouseReleaseEvent(evt)

eric ide

mercurial