Results 1 to 5 of 5

Thread: QPushButton color and background

  1. #1
    Join Date
    May 2010
    Posts
    8
    Qt products
    Qt4

    Default QPushButton color and background

    What's the simplest way to change a button fonts color & background?
    I've tried style sheets and came up with something like this (but it doesn't work)

    Qt Code:
    1. QPushButton *friends = new QPushButton("Friends", imageLabel);
    2. friends->setFlat(true);
    3. QObject::connect(friends, SIGNAL(clicked()),
    4. this, SLOT(updateHitPoints()));
    5. friends-> move(180,270);
    6.  
    7. friends->setStyleSheet("background-color: yellow");
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton color and background

    What doesn't work?
    Got to keep the loonies on the path ...

  3. #3
    Join Date
    May 2010
    Posts
    8
    Qt products
    Qt4

    Default Re: QPushButton color and background

    the button has yellow bacground only when it is pressed
    is it because the
    Qt Code:
    1. friends->setFlat(true);
    To copy to clipboard, switch view to plain text mode 
    ?
    if yes- can i have a "flat" button with yellow background?

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QPushButton color and background

    To quote the documentation:

    If this property is set, most styles will not paint the button background unless the button is being pressed.
    So yes, when you use setFlat, it doesn't work the way you want.

    Try using QPushButton:flat in your stylesheet, and set the background in there.

    However, why do you even want to use setFlat (why did Nokia even include it?). You can get something completely similar using a stylesheet.

    http://doc.qt.nokia.com/4.6/styleshe...ng-qpushbutton

  5. #5
    Join Date
    May 2010
    Posts
    8
    Qt products
    Qt4

    Default Re: QPushButton color and background

    didn't know about that feature, thanks

    one more thing: how do You include a .qss file in a VS 2008 project? so it can be properly compiled?

Similar Threads

  1. Replies: 0
    Last Post: 22nd February 2010, 09:30
  2. QPushButton
    By anafor2004 in forum Newbie
    Replies: 1
    Last Post: 21st October 2009, 16:31
  3. QPushButton grayed out
    By stefan1981 in forum Qt Programming
    Replies: 2
    Last Post: 9th January 2009, 14:27
  4. Qpushbutton
    By iamhere in forum Qt Programming
    Replies: 5
    Last Post: 15th October 2008, 04:40
  5. Replies: 3
    Last Post: 26th September 2006, 12:16

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.