|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a clickable label. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSignal, Qt, QPoint |
|
13 from PyQt5.QtWidgets import QLabel |
|
14 |
|
15 |
|
16 class E5ClickableLabel(QLabel): |
|
17 """ |
|
18 Class implementing a clickable label. |
|
19 |
|
20 @signal clicked(QPoint) emitted upon a click on the label |
|
21 with the left button |
|
22 @signal middleClicked(QPoint) emitted upon a click on the label |
|
23 with the middle button or CTRL and left button |
|
24 """ |
|
25 clicked = pyqtSignal(QPoint) |
|
26 middleClicked = pyqtSignal(QPoint) |
|
27 |
|
28 def __init__(self, parent=None): |
|
29 """ |
|
30 Constructor |
|
31 |
|
32 @param parent reference to the parent widget (QWidget) |
|
33 """ |
|
34 super(E5ClickableLabel, self).__init__(parent) |
|
35 |
|
36 self.setCursor(Qt.PointingHandCursor) |
|
37 |
|
38 def mouseReleaseEvent(self, evt): |
|
39 """ |
|
40 Protected method handling mouse release events. |
|
41 |
|
42 @param evt mouse event (QMouseEvent) |
|
43 """ |
|
44 if evt.button() == Qt.LeftButton and self.rect().contains(evt.pos()): |
|
45 if evt.modifiers() == Qt.ControlModifier: |
|
46 self.middleClicked.emit(evt.globalPos()) |
|
47 else: |
|
48 self.clicked.emit(evt.globalPos()) |
|
49 elif evt.button() == Qt.MidButton and \ |
|
50 self.rect().contains(evt.pos()): |
|
51 self.middleClicked.emit(evt.globalPos()) |
|
52 else: |
|
53 super(E5ClickableLabel, self).mouseReleaseEvent(evt) |