单击按钮后,我想使 qtooltip 消息持久化。我打算稍后使用 qtimer 自己隐藏它,但问题是一旦我将鼠标光标从按钮 rect 移开,消息就会消失,我想让它留在那里,直到稍后我打电话hideText()
from PyQt4 import QtGui, QtCore
from functools import partial
class MyDialog(QtGui.QDialog):
def __init__(self, parent=None):
super(MyDialog, self).__init__(parent)
layout = QtGui.QVBoxLayout()
btn = QtGui.QPushButton('Push Me')
layout.addWidget(btn)
self.setLayout(layout)
btn.clicked.connect(partial(self.showFloatingMessage,'This is a long message'))
def showFloatingMessage(self, message='', delay=500):
desktop = QtGui.QApplication.desktop()
screen_num = desktop.screenNumber(QtGui.QCursor.pos())
screen_rect = desktop.screenGeometry(screen_num)
QtGui.QToolTip.showText(screen_rect.center(), message, None, screen_rect)
app = QtGui.QApplication([])
dialog = MyDialog()
dialog.show()
app.exec_()