E5Gui/E5ClickableLabel.py

changeset 1963
9c5b3235abf9
child 2302
f29e9405c851
diff -r 2e7f691cade9 -r 9c5b3235abf9 E5Gui/E5ClickableLabel.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/E5Gui/E5ClickableLabel.py	Sun Jul 29 15:41:58 2012 +0200
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a clickable label.
+"""
+
+from PyQt4.QtCore import pyqtSignal, Qt, QPoint
+from PyQt4.QtGui import QLabel
+
+
+class E5ClickableLabel(QLabel):
+    """
+    Class implementing a clickable label.
+    
+    @signal clicked(QPoint) emitted upon a click on the label
+            with the left buton
+    @signal middleClicked(QPoint) emitted upon a click on the label
+            with the middle buton or CTRL and left button
+    """
+    clicked = pyqtSignal(QPoint)
+    middleClicked = pyqtSignal(QPoint)
+    
+    def __init__(self, parent=None):
+        """
+        Constructor
+        
+        @param parent reference to the parent widget (QWidget)
+        """
+        super().__init__(parent)
+    
+    def mouseReleaseEvent(self, evt):
+        """
+        Protected method handling mouse release events.
+        
+        @param evt mouse event (QMouseEvent)
+        """
+        if evt.button() == Qt.LeftButton and self.rect().contains(evt.pos()):
+            if evt.modifiers() == Qt.ControlModifier:
+                self.middleClicked.emit(evt.globalPos())
+            else:
+                self.clicked.emit(evt.globalPos())
+        elif evt.button() == Qt.MiddleButton and self.rect().contains(evt.pos()):
+            self.middleClicked.emit(evt.globalPos())
+        else:
+            super().mouseReleaseEvent(evt)

eric ide

mercurial