PDA

View Full Version : Change Font of QListWidget to Monospace Font



pospiech
25th July 2008, 12:33
I use a QListWidget to display data in a column like way:
number: command: value

However, though all commands have the same length and the numbers always take the same space everything is no displayed in the right spacing. Therefore I need to change the font used to display the text inside the listwidget in a monospaced font.

So my question is: How do I change the font used inside the listwidget?

Matthias

salmanmanekia
25th July 2008, 12:48
So my question is: How do I change the font used inside the listwidget?
use the QWidget::setFont() function http://doc.trolltech.com/4.4/qwidget.html#font-prop

pospiech
25th July 2008, 13:11
The following has no effect at all:


QFont font;
font.setStyleHint(QFont::Serif); //QFont::TypeWriter
listWidget_MacroCommands->setFont(font);

The Font still is the default one.

Matthias

salmanmanekia
25th July 2008, 18:23
try this, i hope it works...


QFont font;
font.setStyleHint(QFont::Serif);
font.setFamily( /*include your text here(as QString) */);
listWidget_MacroCommands->setFont(font);

for more details see http://doc.trolltech.com/4.4/qfont.html#setFamily