PDA

View Full Version : Setting specific entries of a QComboBox to appear Bold



prykHetQuo
19th March 2009, 12:47
OS: Ubuntu 8.10 x64

Qt version: Qt 4.4.3.


I create a QComboBox object and I add some entries. How can I make some of them appear in Bold, while others appear as normal?


I tried the following approach, but it doesn't work:



locationComboBox->setFont(QFont("DejaVu Sans", 10, QFont::Bold));
locationComboBox->addItem("This option is Bold:");
locationComboBox->setFont(QFont("DejaVu Sans", 9, QFont::Normal));


Thanks.

wysota
19th March 2009, 13:09
You can try using QCombobox::setItemData() with Qt::FontRole role.

prykHetQuo
20th March 2009, 12:37
May you provide a more specific example?

The following do not make the entry appear in Bold:



locationComboBox->addItem("Test:", Qt::FontRole));

locationComboBox->addItem("Test:", QFont::Bold));

Lykurg
20th March 2009, 14:17
locationComboBox->addItem("Test:", Qt::FontRole));

Huh, wysota said QCombobox::setItemData() and addItem is not setItemData. But today I am friendly because it's Friday:

// sets the second item bold
locationComboBox->setItemData(1, QFont("DejaVu Sans", 10, QFont::Bold), Qt::FontRole);

NOTE: not all style respect these settings...

prykHetQuo
21st March 2009, 10:28
Unfortunately after adding an item to the QComboBox object, the following compiles but it doesn't work.

locationComboBox->setItemData(0, QFont("DejaVu Sans", 10, QFont::Bold), Qt::FontRole);

Lykurg
21st March 2009, 10:59
Look:
NOTE: not all style respect these settings...

What style do you use?

prykHetQuo
23rd March 2009, 19:51
The default of Qt Designer 4.4.3.

wysota
23rd March 2009, 23:11
Designer doesn't reinforce any styles. What desktop do you use? KDE? Gnome? Also run your application with -style X where X stands for different style names (such as plastique, windows or cleanlooks). See if any of them works.