Results 1 to 5 of 5

Thread: changing button background color

  1. #1
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default changing button background color

    Hello!

    I've got some buttons on my main window. Each button is setting page on QStackedWidget. I want to change color of a button which was clicked. Is there any other way than using setStyleSheet? I'm asking because my stylesheet is quite complicated, and I want to change just background color. Any ideas?

    thanks in advance
    best regards
    Tomasz

  2. #2
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: changing button background color

    hi,

    u can use QPalette

    Qt Code:
    1. QPalette p=palette();
    2. p.setBrush(QPalette::Button,Qt::yellow);
    3. p.setBrush(QPalette::ButtonText, Qt::blue);
    4. b->setPalette(p);
    To copy to clipboard, switch view to plain text mode 

    hope it helps
    bala
    Last edited by BalaQT; 25th November 2010 at 11:17.

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

    Tomasz (25th November 2010)

  4. #3
    Join Date
    Apr 2010
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: changing button background color

    Third party here:

    That will make the button a solid color, is there a way to change the button color with shades, so it looks like a modern button. Like it does by default, except chaning the theme color.

    Any suggestions?

  5. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: changing button background color

    There is no simple way to do this with palettes or stylesheets. On some operating systems it will work, but others (<cough>Windows<cough>) do not allow button backgrounds to be altered. The only foolproof way to do this is to derive your own button class and override the paint method.

  6. #5
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: changing button background color

    Third party here:

    That will make the button a solid color, is there a way to change the button color with shades, so it looks like a modern button. Like it does by default, except chaning the theme color.

    Any suggestions?
    To make the shade in buttons , u can use stylesheets's transparent property or u can design ur own images and apply to the button;

    for Gradient:
    Qt Code:
    1. QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #88d, stop: 0.1 #99e, stop: 0.49 #77c, stop: 0.5 #66b, stop: 1 #77c);
    To copy to clipboard, switch view to plain text mode 

    for images :
    Qt Code:
    1. background-image: url(/path/to/image.png);
    To copy to clipboard, switch view to plain text mode 

    Hope it helps

    Bala

Similar Threads

  1. Changing the background color of a cell in a QTableView
    By scarleton in forum Qt Programming
    Replies: 1
    Last Post: 30th June 2010, 13:23
  2. button background color when it is clicked
    By navi1084 in forum Qt Programming
    Replies: 4
    Last Post: 9th December 2008, 15:02
  3. changing color of push button
    By babu198649 in forum Newbie
    Replies: 1
    Last Post: 2nd March 2008, 12:55
  4. prob with changing QLineEdit background color
    By Ahmad in forum Qt Programming
    Replies: 2
    Last Post: 30th April 2007, 12:44

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.