PDA

View Full Version : How is it easier to change font properties?



alex chpenst
11th July 2008, 08:06
Hi,
I'm trying to find the easiest way to change font parameters for different text in widgets. Using html code would be fine, but it seems to not work everywhere for me... For example to write a string in italic in the ListWidget I do the following:


QListWidgetItem *item = new QListWidgetItem("Text...");
QFont *font = new QFont;
font->setItalic(true);
item->setFont(*font);
listWidget->insertItem(0,item);

...which is a quite long way. How to do it simpler?
If I write "<i>Text...</i>" instead of "Text..." this doesn't work.

Thanks!!

jacek
11th July 2008, 20:01
QFont *font = new QFont;
...
item->setFont(*font);
I hope you know that, if you won't delete that QFont object, you will get a memory leak. It's better to create that QFont on the stack in this case.


...which is a quite long way. How to do it simpler?
Write a createItalicListWidgetItemOrWhatever() function or subclass QListWidgetItem to make it understand rich text. Depending on what you want to achieve, you can also try style sheets.