Results 1 to 7 of 7

Thread: Style Sheet color of QComboBox

  1. #1
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Style Sheet color of QComboBox

    I created the following slot, and code to link the signal I wanted to it:

    Qt Code:
    1. //connection:
    2. connect(ui.vendor_status, SIGNAL( activated (int) ), this, SLOT(colorBackgroundcombo() ) );
    3.  
    4.  
    5. // slot:
    6. //color the background of the combo box that called the slot:
    7. void FabwareMain::colorBackgroundcombo() {
    8. //enable the save button since we have edited something:
    9. ui.actionSave->setEnabled(true);
    10. //color the combobox yellow since we changed it
    11. QComboBox* comboBox = qobject_cast<QComboBox*>(sender());
    12. if (comboBox) {
    13. comboBox->setStyleSheet(QString("background-color: yellow"));
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    The program compiled fine, however when executed only ui.actionSave is set to true when any of the comboboxes that are connected to this slot are changed.

    I then did an experiment and changed the slot to this:
    (the slot would change a style of a specific combobox and line edit field instead of using sender())
    Qt Code:
    1. //color the background of the combo box that called the slot:
    2. void FabwareMain::colorBackgroundcombo() {
    3. //enable the save button since we have edited something:
    4. ui.actionSave->setEnabled(true);
    5. ui.vendor_state->setStyleSheet(QString("background-color: yellow"));
    6. ui.vendor_zip->setStyleSheet(QString("background-color: yellow"));
    7. }
    To copy to clipboard, switch view to plain text mode 
    After changing to my test slot, when the slot is called, actionSave is enabled, vendor_zip is colored to yellow, however the QComboBox vendor_state is still white.

    I would think this means that for some reason the QComboBox is not taking the style from setStyleSheet(), however I can find no error output either during runtime or compile that would indicate why.

    Could anyone point me in the right direction on the stylesheet for QComboBox, (or an alternate coloring method if the styles do not work for it)?

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

    Default Re: Style Sheet color of QComboBox

    Do you use 4.2 or 4.3? And which widget style?

  3. #3
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Style Sheet color of QComboBox

    I am using QT 4.2.3 open source and the issue happens when I compile on windows XP (I assume thats what you mean by "widget style". If you would like I can also see what happens in linux as I have everything set up to compile for that as well.

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

    Default Re: Style Sheet color of QComboBox

    Run your application with -style Plastique parameters and see if the behaviour persists.

  5. #5
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Style Sheet color of QComboBox

    Ok, Heres something interesting. I ran it in all styles including plastique to see what would happen, and I got the exact same results as I described with the windows XP style, except in the CDE style. Heres what happened:

    -When the form is untouched in CDE and classic windows style, the comboboxes are raised, but they are white. When the test slot is activated, the ui.vendor_state combobox becomes grey, and the ui.vendor_zip line edit becomes yellow.

    -In the classic windows style, the same thing happens as in the CDE, except instead of the whole combobox turning grey on activation of the slot, only the tiny drop arrow on the right hand side turns from white to grey.

    I notice that the plastique or cleanlooks style, the comboboxes are a shiny gray color when you are not in the process of selecting an item from them. It seems like this can't be changed.

    In the windows XP style, the comboboxes are text with a white background but still won't take the style. They look like they could be changed, but maybe they somehow inherit the same traits as plastique/cleanlooks.

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

    Default Re: Style Sheet color of QComboBox

    I suggest you upgrade your Qt installation. You might be suffering from some kind of bug. Stylesheets are a quite new technology in Qt and still contain many bugs. The sheet seems to work fine on my 4.3-based installation.

  7. The following user says thank you to wysota for this useful post:

    tpf80 (25th June 2007)

  8. #7
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Style Sheet color of QComboBox

    Yes that fixed it, after upgrading to Qt 4.3 and re-compiling my program, the QComboBox takes the style like expected.

Similar Threads

  1. Qt 4.3 Style sheet, new features
    By Angelo Moriconi in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2007, 16:22
  2. Qt Designer Style Sheet Resources
    By bjoernbg in forum Newbie
    Replies: 1
    Last Post: 24th January 2007, 08:12
  3. How to use style sheet
    By safknw in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2006, 14:05
  4. QComboBox and style
    By Lele in forum Qt Programming
    Replies: 3
    Last Post: 17th July 2006, 17:41

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.