|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a clickable label. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSignal, Qt, QPoint |
|
11 from PyQt4.QtGui 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 buton |
|
20 @signal middleClicked(QPoint) emitted upon a click on the label |
|
21 with the middle buton 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 def mouseReleaseEvent(self, evt): |
|
35 """ |
|
36 Protected method handling mouse release events. |
|
37 |
|
38 @param evt mouse event (QMouseEvent) |
|
39 """ |
|
40 if evt.button() == Qt.LeftButton and self.rect().contains(evt.pos()): |
|
41 if evt.modifiers() == Qt.ControlModifier: |
|
42 self.middleClicked.emit(evt.globalPos()) |
|
43 else: |
|
44 self.clicked.emit(evt.globalPos()) |
|
45 elif evt.button() == Qt.MiddleButton and self.rect().contains(evt.pos()): |
|
46 self.middleClicked.emit(evt.globalPos()) |
|
47 else: |
|
48 super().mouseReleaseEvent(evt) |