Results 1 to 5 of 5

Thread: QtDesigner and Stylesheets

  1. #1
    Join Date
    Jan 2008
    Location
    Vancouver, Canada
    Posts
    54
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QtDesigner and Stylesheets

    Hello,

    I am trying to apply a style sheet stored in a file to my application. In particular, I would like to add padding to my QCombo-boxes, as such:

    Qt Code:
    1. padding: 3px;
    2. color: red;
    3. }
    To copy to clipboard, switch view to plain text mode 

    Note that I have added the red for testing purposes. I have several QComboBoxes, created in Qt Designer. If I apply the style sheet to the entire application (using
    Qt Code:
    1. qApp()->setStyleSheet(styleSheet)
    To copy to clipboard, switch view to plain text mode 
    ), the text turns red but does not add the padding. This means that I am correctly reading in the text file and applying it, but I am somehow not setting the padding property properly.

    Again, I tried setting the style sheet in the source code file that sets up the *.ui file.
    This works:
    Qt Code:
    1. this->setStyleSheet("QComboBox { color: red; }");
    To copy to clipboard, switch view to plain text mode 

    This doesn't:
    Qt Code:
    1. this->setStyleSheet("QComboBox { padding: 3px; }");
    To copy to clipboard, switch view to plain text mode 

    I can successfully pad them by adding a line of code for each:
    Qt Code:
    1. ui->ComboBox->setStyleSheet("QComboBox { padding: 3 px; }");
    To copy to clipboard, switch view to plain text mode 

    I can successfully change the style sheet in Qt Designer.

    However, both of the solutions above must be done for each combo box, which is tedious and (I think) unnecessary. Any help would be greatly appreciated. Thanks,

    AB

    edit: I am using Qt Designer with Qt Creator on a 64 bit Windows 7 machine. I am using Qt version 4.7.4 (32 bit).
    Last edited by abrou; 4th September 2012 at 22:56. Reason: Updating user-specific information

  2. #2
    Join Date
    Jul 2010
    Location
    Indonesia
    Posts
    83
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: QtDesigner and Stylesheets

    Qt Code:
    1. int main(int argc , char* argv[])
    2. {
    3. QApplication app(argc, argv);
    4. app.setStyleSheet("QComboBox{padding:3px;color:red;}");
    5.  
    6. MainWidget mainWidget;
    7. mainWidget.show();
    8.  
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 
    The codes above should apply stylesheets to all QComboBox instances in the application. If not, try creating new widget with combobox within it to make sure you don't have inline stylesheet replacing the initial stylesheets apllied.
    ~ We are nothing in this universe ~

  3. The following user says thank you to viulskiez for this useful post:

    abrou (5th September 2012)

  4. #3
    Join Date
    Jan 2008
    Location
    Vancouver, Canada
    Posts
    54
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtDesigner and Stylesheets

    Thanks for your reply. I tested the exact code you provided with the same results. Red text but no padding. I added a new ComboBox to a new widget and it worked as expeted; it was red and padded. From what you've said, I have an inline stylesheet replacing my style sheet. As far as I can tell, I haven't added it myself, but is it possible I inadvertently changed the style sheet using Qt Designer? I played around with the style sheet in Designer, but deleted it because I wanted to have a single style sheet for my entire application.

    Thanks,

    AB

  5. #4
    Join Date
    Jul 2010
    Location
    Indonesia
    Posts
    83
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: QtDesigner and Stylesheets

    As far as I can tell, I haven't added it myself, but is it possible I inadvertently changed the style sheet using Qt Designer?
    Of course it's possible. If necessary, you can modify .ui file manually with text editor (not Qt Designer) to make sure the inline style sheet have been properly removed.
    ~ We are nothing in this universe ~

  6. The following user says thank you to viulskiez for this useful post:

    abrou (5th September 2012)

  7. #5
    Join Date
    Jan 2008
    Location
    Vancouver, Canada
    Posts
    54
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtDesigner and Stylesheets

    Thanks. I assumed that if QT Designer didn't display anything in the StyleSheet textbox that it wasn't adding anything to the *.ui file. Bad assumption on my part. I'll delve into it now. Thanks again.

    Edit: As you suggested, I had played with the style sheets in Qt Designer. I had deleted them, but they remained in the *.ui which I could delete manually. This is now solved.
    Last edited by abrou; 5th September 2012 at 19:06. Reason: updated contents

Similar Threads

  1. Another Question with StyleSheets
    By daiheitan in forum Qt Programming
    Replies: 7
    Last Post: 12th March 2010, 11:29
  2. Where to put my stylesheets?
    By martinn in forum Qt Programming
    Replies: 3
    Last Post: 2nd February 2010, 15:28
  3. Working with StyleSheets
    By BingoMaster in forum Newbie
    Replies: 3
    Last Post: 29th September 2009, 16:52
  4. Stylesheets
    By FuryCradle in forum Newbie
    Replies: 2
    Last Post: 26th September 2009, 21:34
  5. stylesheets with RGB
    By tommy in forum Qt Programming
    Replies: 4
    Last Post: 13th December 2007, 01: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.