Profile menu tooltips
[stack/code/dboxswitch.git] / qmenutooltip.py
diff --git a/qmenutooltip.py b/qmenutooltip.py
new file mode 100644 (file)
index 0000000..486a3ad
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/python
+
+from PyQt4 import QtGui, QtCore
+class QMenuToolTip(QtGui.QMenu):
+    """ Implements a QMenu where it is possible to set a ToolTip and display it on mouse hover """
+    def __init__(self, parent=None):
+        QtGui.QMenu.__init__(self, parent)
+
+    def event(self, e):
+        if e.type() == QtCore.QEvent.ToolTip:
+            if not self.activeAction() is None:
+                QtGui.QToolTip.showText(e.globalPos(), self.activeAction().toolTip())
+            else:
+                QtGui.QToolTip.hideText()
+        return QtGui.QMenu.event(self, e)