Show More
@@ -21,6 +21,8 b' class CallTipWidget(QtGui.QLabel):' | |||
|
21 | 21 | assert isinstance(parent, (QtGui.QTextEdit, QtGui.QPlainTextEdit)) |
|
22 | 22 | QtGui.QLabel.__init__(self, parent, QtCore.Qt.ToolTip) |
|
23 | 23 | |
|
24 | self._hide_timer = QtCore.QBasicTimer() | |
|
25 | ||
|
24 | 26 | self.setFont(parent.document().defaultFont()) |
|
25 | 27 | self.setForegroundRole(QtGui.QPalette.ToolTipText) |
|
26 | 28 | self.setBackgroundRole(QtGui.QPalette.ToolTipBase) |
@@ -52,12 +54,31 b' class CallTipWidget(QtGui.QLabel):' | |||
|
52 | 54 | elif etype == QtCore.QEvent.FocusOut: |
|
53 | 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 | 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 | 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 | 82 | def hideEvent(self, event): |
|
62 | 83 | """ Reimplemented to disconnect signal handlers and event filter. |
|
63 | 84 | """ |
@@ -66,6 +87,12 b' class CallTipWidget(QtGui.QLabel):' | |||
|
66 | 87 | parent.cursorPositionChanged.disconnect(self._cursor_position_changed) |
|
67 | 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 | 96 | def paintEvent(self, event): |
|
70 | 97 | """ Reimplemented to paint the background panel. |
|
71 | 98 | """ |
@@ -167,6 +194,12 b' class CallTipWidget(QtGui.QLabel):' | |||
|
167 | 194 | position = -1 |
|
168 | 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 | 203 | #------ Signal handlers ---------------------------------------------------- |
|
171 | 204 | |
|
172 | 205 | def _cursor_position_changed(self): |
General Comments 0
You need to be logged in to leave comments.
Login now