Results 1 to 3 of 3

Thread: stylesheet help nedded

  1. #1
    Join Date
    Sep 2008
    Posts
    84
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default stylesheet help nedded

    I have declared new button and assgin stylesheet to it.
    Qt Code:
    1. button = new QPushButton(this);
    2. button->setText("TEST");
    3. button->setGeometry(400,50,70,40);
    4. button->setStyleSheet(
    5. "color:white;\n"
    6. "background:rgb(255,255,0);"
    7. "border-radius:10px;\n"
    8. "font:bold 16px;\n"
    9. "font-family:\"Arial\";\n"
    10. );
    To copy to clipboard, switch view to plain text mode 

    my the problem is: how to apply the below code

    QPushButton:Pressed {
    padding-left: 5px;
    padding-top: 5px;
    }

  2. #2
    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: stylesheet help nedded

    Hi, use normal CSS selectors:
    Qt Code:
    1. button->setStyleSheet(
    2. "QPushButton {color:white; background:rgb(255,255,0); border-radius:10px; font:bold 16px; font-family:\"Arial\";}"
    3. "QPushButton:Pressed {padding-left: 5px; padding-top: 5px;}"
    4. );
    To copy to clipboard, switch view to plain text mode 

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

    aj2903 (14th February 2009)

  4. #3
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: stylesheet help nedded

    there is also another way to do this.. use an external file and put all stylesheet code there..then load that file for loading the stylesheet of WHOLE application all at once..that way ur stylesheet code for pushbutton and other widgets wont be scattered around the whole project..and u wont have to make any changes in the code itself when u want a change to the look of the UI..all u'll have to do is change that external file..u can do it like this:

    Qt Code:
    1. QString strCurTheme = "styles.qss";
    2. QFile file(strCurTheme );
    3. file.open(QFile::ReadOnly);
    4. application.setStyleSheet(file.readAll());
    To copy to clipboard, switch view to plain text mode 

  5. The following 2 users say thank you to talk2amulya for this useful post:

    aj2903 (14th February 2009), thanyaj (11th November 2010)

Similar Threads

  1. Replies: 7
    Last Post: 12th January 2011, 22:01
  2. StyleSheet syntax checking
    By MarkoSan in forum Qt Programming
    Replies: 5
    Last Post: 30th June 2008, 10:09
  3. StyleSheet components using Qt designer
    By Kostanev in forum Qt Tools
    Replies: 1
    Last Post: 21st April 2008, 08:28
  4. how to apply stylesheet to qtopia application using qss file
    By namita in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 31st March 2008, 07:04
  5. Replies: 8
    Last Post: 17th March 2008, 14:04

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.