-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from qtpy.QtCore import QObject, QEvent | ||
from qtpy.QtGui import QCursor | ||
from qtpy.QtWidgets import QWidget, QToolTip | ||
|
||
|
||
class InstantTooltipEventFilter(QObject): | ||
def __init__(self, parent=None): | ||
super(InstantTooltipEventFilter, self).__init__(parent) | ||
|
||
def eventFilter(self, watched: QObject, event: QEvent) -> bool: | ||
print('event') | ||
if isinstance(watched, QWidget) and event.type() == QEvent.Enter: | ||
print('show') | ||
QToolTip.showText(QCursor.pos(), watched.toolTip()) | ||
elif event.type() == QEvent.Leave: | ||
QToolTip.hideText() | ||
|
||
return super(InstantTooltipEventFilter, self).eventFilter(watched, event) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from qtpy.QtWidgets import QPushButton, QToolTip | ||
|
||
from qthandy.filter import InstantTooltipEventFilter | ||
|
||
|
||
def test_instant_tooltip(qtbot): | ||
btn = QPushButton('Button') | ||
qtbot.addWidget(btn) | ||
btn.show() | ||
|
||
btn.setToolTip('Test button') | ||
btn.installEventFilter(InstantTooltipEventFilter(btn)) | ||
qtbot.mouseMove(btn) | ||
|
||
assert QToolTip.isVisible() |