[PyQt] Fonts on Macbook

Colin McPhail colin.mcphail at talktalk.net
Sat Feb 13 22:10:07 GMT 2010


On 13 Feb 2010, at 20:17, David Arnold wrote:

> 
> No matter what changes I make to this line:
> 
>        QtGui.QToolTip.setFont(QtGui.QFont('Arial', 20))
> 
> The results are always the same. Are there any Mac users out there who can actually change fonts and fontsize in this script?
> 
I confirm that this does not seem to have any effect on Mac.  However, you can change the appearance of tooltips by using a stylesheet:

import sys
from PyQt4 import QtGui
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')

       tip_style = """
QToolTip {
     border: 2px solid green;
     border-radius: 4px;
     padding: 2px;
     font-family: "Arial";
     font-size: 20pt;
 }
 """
       self.setStyleSheet(tip_style)

       self.setToolTip('This is a <b>QWidget</b> widget')


app=QtGui.QApplication(sys.argv)
tp=Tooltip()
tp.show()
sys.exit(app.exec_())

If you want all tooltips to have the same non-default appearance then I think that you could use QApplication's setStyleSheet method instead of QWidget's one.

-- CMcP



More information about the PyQt mailing list