Results 1 to 9 of 9

Thread: Style Sheet Problem

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Style Sheet Problem

    Hi,

    I want to know that is it possible to give a background color to the buttons inside a frame from the source code by not setting the style sheets of each button one by one. Notably, this background color should be set after a button is pressed! I type something like the following but it did not work!

    myMainFrame.setStyleSheet(" QPushButtonressed{ background-color: red}");

    Regards

  2. #2
    Join Date
    Jan 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Style Sheet Problem

    I had a similar problem in a project I was working on recently.

    try this code:

    Qt Code:
    1. myMainFrame.setStyleSheet(" QPushButton:pressed{ background-color: red; border-style: outset; }");
    To copy to clipboard, switch view to plain text mode 

    I had to set the border-style property in order to get the background colors to work at all in my stylesheet. HTH

  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Style Sheet Problem

    Hi,

    Thanks for your response but it doesn't work either

  4. #4
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Style Sheet Problem

    Try
    Qt Code:
    1. QPushButton:pressed { background-color: red; border: none; }
    To copy to clipboard, switch view to plain text mode 

    You can find much useful information here http://doc.trolltech.com/4.4/stylesheet-reference.html
    C++ & AMD forever

  5. #5
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Style Sheet Problem

    Hi,

    Yes you're right THRES but unfortunately that's what I have been doing since 2 weeks.
    I will try your solution and report back to you as soos as possible.

    Regards,

  6. #6
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Style Sheet Problem

    Hi,

    Sorry for the late response, but it didn't work either.

    Regards.

  7. #7
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Style Sheet Problem

    Maybe you can try a different approach with setPalette(). The palette is inherited from the parent, so if you set the right palette of the frame that is equivalent to the palette that is applied on a pressed button it might work.

  8. #8
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Style Sheet Problem

    Hi,

    I didn't try the palette because it should work by doing,

    myMainFrame.setStyleSheet(" QPushButtonressed{ background-color: red; border-style: outset; }");

    When I do it from the designer button by button it works OK but from my application's main method, it doesn't. More interestingly, border stuffs work but background-color.

    Any more ideas?
    Last edited by zgulser; 17th February 2009 at 07:55.

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

    Default Re: Style Sheet Problem

    Try this

    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 

Similar Threads

  1. QMenu style sheet: works in dev env, breaks in release
    By JimDaniel in forum Qt Programming
    Replies: 1
    Last Post: 6th October 2008, 19:18
  2. Style Sheet speed
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 24th January 2008, 18:40
  3. QToolButton and Style sheet
    By desch in forum Qt Programming
    Replies: 8
    Last Post: 1st December 2007, 08:38
  4. QToolBox qss style sheet problem
    By eskil in forum Qt Programming
    Replies: 1
    Last Post: 17th August 2007, 17:45
  5. Qt 4.3 Style sheet, new features
    By Angelo Moriconi in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2007, 15:22

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.