eric7/E5Gui/E5ClickableLabel.py

branch
eric7
changeset 8312
800c432b34c8
parent 8218
7c09585bd960
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
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 PyQt5.QtCore import pyqtSignal, Qt, QPoint
11 from PyQt5.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.pos())
45 ):
46 if evt.modifiers() == Qt.KeyboardModifier.ControlModifier:
47 self.middleClicked.emit(evt.globalPos())
48 else:
49 self.clicked.emit(evt.globalPos())
50 elif (
51 evt.button() == Qt.MouseButton.MidButton and
52 self.rect().contains(evt.pos())
53 ):
54 self.middleClicked.emit(evt.globalPos())
55 else:
56 super().mouseReleaseEvent(evt)

eric ide

mercurial