I'm getting started with PyQt4 and tested the following code...
import sys
from PyQt4 import Qt开发者_运维百科Gui
from PyQt4 import QtCore
class Tooltip(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Tooltip')
self.setToolTip('This is a <b>QWidget</b> widget')
QtGui.QToolTip.setFont(QtGui.QFont('OldEnglish', 10))
app = QtGui.QApplication(sys.argv)
tooltip = Tooltip()
tooltip.show()
sys.exit(app.exec_())
However, no tooltip shows up! I'm on Ubuntu 10.04. I also tried an icon and that didn't work either.
If the window you start your application from ( e.g. your terminal ) is active, hovering over your application will not show a Tooltip. As Ivo indicated you need to make the window of your application active for the Tooltips to show up.
精彩评论