Results 1 to 4 of 4

Thread: stylesheet question

  1. #1
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default stylesheet question

    Hi,
    Imagine i have a Dialog (myDialog) with 3 QLineEdit objects: lineEdit1, lineEdit2, lineEdit3. I am using QtDesiner so i have 4 files:
    • main.cpp
    • myDialog.h
    • myDialog.cpp
    • myDialog.ui


    If i want to apply a red color to the background off all lineEdits in the application e use, in main.cpp the following:
    Qt Code:
    1. app.setStyleSheet("QLineEdit { background-color: red }");
    To copy to clipboard, switch view to plain text mode 

    Now supose i want to apply other stylesheet color as the Dialog level. Where showld i place the code:
    Qt Code:
    1. myDialog->setStyleSheet("QLineEdit { background-color: yellow }");
    To copy to clipboard, switch view to plain text mode 
    ?
    Thanks

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: stylesheet question

    myDialog->setStyleSheet(" background-color: yellow "); should do it.
    When specifying QLineEdit in that line, it means for all line edits in that dialog

  3. #3
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default Re: stylesheet question

    humm ... i don't think i explained myself well.
    Imagine this situation:
    Qt Code:
    1. #include <QApplication>
    2.  
    3. #include "Dialog_1.h"
    4. #include "Dialog_2.h"
    5.  
    6. int main(int argc, char *argv[]){
    7. QApplication app(argc, argv);
    8.  
    9. //apply stylesheet at application level
    10. app.setStyleSheet("QLineEdit { background-color: red }");
    11.  
    12. Dialog_1 *dialog1 = new Dialog_1;
    13. Dialog_2 *dialog2 = new Dialog_2;
    14. dialog1->show();
    15. dialog2->show();
    16. return app.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 

    Both dialogs will show the color red on all lineedits, right?
    Now imagine that dialog 2 is meant to be an exception, and i can not edit main.cpp.
    Where in the .h, .ui or .cpp do i apply the overriding stylesheet?
    Hope this makes any sense

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: stylesheet question

    Use selectors, for example object name.
    J-P Nurmi

Similar Threads

  1. Replies: 7
    Last Post: 12th January 2011, 22:01
  2. Styling QComoBox using CSS Stylesheet
    By bjoernbg in forum Qt Programming
    Replies: 1
    Last Post: 6th October 2010, 23:12
  3. Plugin implementation question
    By JPNaude in forum Qt Programming
    Replies: 12
    Last Post: 27th August 2008, 20:24
  4. Replies: 1
    Last Post: 15th March 2007, 20:45

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.