##// END OF EJS Templates
The CallTipWidget is now smarter about automatically hiding itself.
epatters -
Show More
@@ -21,6 +21,8 b' class CallTipWidget(QtGui.QLabel):'
21 assert isinstance(parent, (QtGui.QTextEdit, QtGui.QPlainTextEdit))
21 assert isinstance(parent, (QtGui.QTextEdit, QtGui.QPlainTextEdit))
22 QtGui.QLabel.__init__(self, parent, QtCore.Qt.ToolTip)
22 QtGui.QLabel.__init__(self, parent, QtCore.Qt.ToolTip)
23
23
24 self._hide_timer = QtCore.QBasicTimer()
25
24 self.setFont(parent.document().defaultFont())
26 self.setFont(parent.document().defaultFont())
25 self.setForegroundRole(QtGui.QPalette.ToolTipText)
27 self.setForegroundRole(QtGui.QPalette.ToolTipText)
26 self.setBackgroundRole(QtGui.QPalette.ToolTipBase)
28 self.setBackgroundRole(QtGui.QPalette.ToolTipBase)
@@ -52,12 +54,31 b' class CallTipWidget(QtGui.QLabel):'
52 elif etype == QtCore.QEvent.FocusOut:
54 elif etype == QtCore.QEvent.FocusOut:
53 self.hide()
55 self.hide()
54
56
57 elif etype == QtCore.QEvent.Enter:
58 self._hide_timer.stop()
59
60 elif etype == QtCore.QEvent.Leave:
61 self._hide_later()
62
55 return QtGui.QLabel.eventFilter(self, obj, event)
63 return QtGui.QLabel.eventFilter(self, obj, event)
56
64
65 def timerEvent(self, event):
66 """ Reimplemented to hide the widget when the hide timer fires.
67 """
68 if event.timerId() == self._hide_timer.timerId():
69 self._hide_timer.stop()
70 self.hide()
71
57 #--------------------------------------------------------------------------
72 #--------------------------------------------------------------------------
58 # 'QWidget' interface
73 # 'QWidget' interface
59 #--------------------------------------------------------------------------
74 #--------------------------------------------------------------------------
60
75
76 def enterEvent(self, event):
77 """ Reimplemented to cancel the hide timer.
78 """
79 QtGui.QLabel.enterEvent(self, event)
80 self._hide_timer.stop()
81
61 def hideEvent(self, event):
82 def hideEvent(self, event):
62 """ Reimplemented to disconnect signal handlers and event filter.
83 """ Reimplemented to disconnect signal handlers and event filter.
63 """
84 """
@@ -66,6 +87,12 b' class CallTipWidget(QtGui.QLabel):'
66 parent.cursorPositionChanged.disconnect(self._cursor_position_changed)
87 parent.cursorPositionChanged.disconnect(self._cursor_position_changed)
67 parent.removeEventFilter(self)
88 parent.removeEventFilter(self)
68
89
90 def leaveEvent(self, event):
91 """ Reimplemented to start the hide timer.
92 """
93 QtGui.QLabel.leaveEvent(self, event)
94 self._hide_later()
95
69 def paintEvent(self, event):
96 def paintEvent(self, event):
70 """ Reimplemented to paint the background panel.
97 """ Reimplemented to paint the background panel.
71 """
98 """
@@ -167,6 +194,12 b' class CallTipWidget(QtGui.QLabel):'
167 position = -1
194 position = -1
168 return position, commas
195 return position, commas
169
196
197 def _hide_later(self):
198 """ Hides the tooltip after some time has passed.
199 """
200 if not self._hide_timer.isActive():
201 self._hide_timer.start(300, self)
202
170 #------ Signal handlers ----------------------------------------------------
203 #------ Signal handlers ----------------------------------------------------
171
204
172 def _cursor_position_changed(self):
205 def _cursor_position_changed(self):
General Comments 0
You need to be logged in to leave comments. Login now