Results 1 to 4 of 4

Thread: Style Sheets: Change font-style in QComboBox but not in corresponding popup

  1. #1
    Join Date
    Sep 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Style Sheets: Change font-style in QComboBox but not in corresponding popup

    Depending on some dynamic property, I'd like to set the font style in the top-item of a QComboBox to italic, but keep the appearance of the items in the corresponding popup (QListView).

    I tried it with the following qss:

    Qt Code:
    1. QComboBox#librarySettingsBox QListView {
    2. font-style: normal;
    3. /* background-color: rgb(255, 255, 127);*/
    4. }
    5. QComboBox[dirty="true"] {
    6. font-style: italic;
    7. /* background-color: rgb(85, 0, 255);*/
    8. }
    To copy to clipboard, switch view to plain text mode 

    In my C++ code, I call update on the widget after setting the property like this:

    Qt Code:
    1. ui->librarySettingsBox->setProperty("dirty", dirty);
    2. ui->librarySettingsBox->style()->unpolish(ui->librarySettingsBox);
    3. ui->librarySettingsBox->style()->polish(ui->librarySettingsBox);
    4. ui->librarySettingsBox->update();
    To copy to clipboard, switch view to plain text mode 

    The "font-style: normal" setting is supposed to override the italic setting in the QListView, as it has a higher priority due to the id-tag contained. This can also be confirmed by uncommenting the "background-color" tags. However, the font-style does not seem to have any effect on the QListView. Why is it so and how can I fix it?

  2. #2
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Style Sheets: Change font-style in QComboBox but not in corresponding popup

    QComboBox has two different parts the edit box is actually QLineEdit and then PopUp which is I think QListView(Please check this).

    Try to set different stylesheet for both the component for given QComboBox and it should work.

    see below link which gives list of state of any qt control for stylesheet...
    http://qt-project.org/doc/qt-4.8/sty...ml#paletterole

    I have tried one example in which combobox font is italics and dropdown font is normal, below is stylesheet used for that...
    QComboBox {font-style: italic;}
    QComboBox QListView { font-style: normal; }
    Last edited by Rajesh.Rathod; 25th September 2014 at 13:31.

  3. #3
    Join Date
    Sep 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Style Sheets: Change font-style in QComboBox but not in corresponding popup

    Unfortunately, this doesn't work. The problem doesn't seem to be with the selectors, but with applying a font-style to the QListView, as overriding styles in the QListView does work e.g. for background-colors.

    Quote Originally Posted by Rajesh.Rathod View Post
    I have tried one example in which combobox font is italics and dropdown font is normal, below is stylesheet used for that...
    QComboBox {font-style: italic;}
    QComboBox QListView { font-style: normal; }
    Which Version of Qt did you use for that? Maybe I should say I'm using Qt 5.2.1.

  4. #4
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Style Sheets: Change font-style in QComboBox but not in corresponding popup

    Qt 5.1.0 & Qt Creator 2.7.2.

Similar Threads

  1. QComboBox and style sheets
    By Krieger in forum Qt Programming
    Replies: 0
    Last Post: 21st March 2014, 10:02
  2. Do Qt Style Sheets support List-style-image?
    By daiheitan in forum Qt Programming
    Replies: 6
    Last Post: 12th March 2010, 01:41
  3. Style sheets and font weight bug
    By Oleg in forum Qt Programming
    Replies: 8
    Last Post: 14th February 2010, 22:19
  4. How to change cursor using style sheets?
    By 0x815 in forum Newbie
    Replies: 0
    Last Post: 13th September 2009, 13:35
  5. Change color of a link in QLabel using Style Sheets?
    By codeslicer in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2008, 11:00

Tags for this Thread

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.