Results 1 to 8 of 8

Thread: Setting specific entries of a QComboBox to appear Bold

  1. #1
    Join Date
    Jan 2009
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11

    Arrow Setting specific entries of a QComboBox to appear Bold

    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:

    Qt Code:
    1. locationComboBox->setFont(QFont("DejaVu Sans", 10, QFont::Bold));
    2. locationComboBox->addItem("This option is Bold:");
    3. locationComboBox->setFont(QFont("DejaVu Sans", 9, QFont::Normal));
    To copy to clipboard, switch view to plain text mode 

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Setting specific entries of a QComboBox to appear Bold

    You can try using QCombobox::setItemData() with Qt::FontRole role.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2009
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Setting specific entries of a QComboBox to appear Bold

    May you provide a more specific example?

    The following do not make the entry appear in Bold:

    Qt Code:
    1. locationComboBox->addItem("Test:", Qt::FontRole));
    2.  
    3. locationComboBox->addItem("Test:", QFont::Bold));
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Setting specific entries of a QComboBox to appear Bold

    Quote Originally Posted by prykHetQuo View Post
    Qt Code:
    1. locationComboBox->addItem("Test:", Qt::FontRole));
    To copy to clipboard, switch view to plain text mode 
    Huh, wysota said QCombobox::setItemData() and addItem is not setItemData. But today I am friendly because it's Friday:
    Qt Code:
    1. // sets the second item bold
    2. locationComboBox->setItemData(1, QFont("DejaVu Sans", 10, QFont::Bold), Qt::FontRole);
    To copy to clipboard, switch view to plain text mode 

    NOTE: not all style respect these settings...
    Last edited by Lykurg; 20th March 2009 at 14:23.

  5. #5
    Join Date
    Jan 2009
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Setting specific entries of a QComboBox to appear Bold

    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);

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Setting specific entries of a QComboBox to appear Bold

    Look:
    Quote Originally Posted by Lykurg View Post
    NOTE: not all style respect these settings...
    What style do you use?

  7. #7
    Join Date
    Jan 2009
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Setting specific entries of a QComboBox to appear Bold

    The default of Qt Designer 4.4.3.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Setting specific entries of a QComboBox to appear Bold

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Application crashing on setting Model in QComboBox.
    By kaushal_gaurav in forum Qt Programming
    Replies: 6
    Last Post: 13th February 2009, 18:20
  2. Editing and adding entries to a QComboBox
    By bruccutler in forum Newbie
    Replies: 1
    Last Post: 29th May 2007, 17:13
  3. Qt4.1.1: Sorting QCombobox entries
    By Byngl in forum Qt Programming
    Replies: 4
    Last Post: 17th March 2006, 09:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.