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) |
|