Results 1 to 7 of 7

Thread: Get background color of QPushbutton

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Get background color of QPushbutton

    Have you tried the Background or Window roles?

    Cheers,
    _

  2. The following user says thank you to anda_skoa for this useful post:

    MickyJhon (7th February 2014)

  3. #2
    Join Date
    Jan 2014
    Posts
    16
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Get background color of QPushbutton

    hello, anda_skoa:

    According to your opinion ,i use Background or Window roles. however, i don't get the result as i except.

    my code is :

    Qt Code:
    1. QPalette::ColorRole role=ui->btn_curveColor->backgroundRole();
    2. curveColor=ui->btn_curveColor->palette().color(role);
    3. int r=curveColor.red();
    4. int g=curveColor.green();
    5. int b=curveColor.blue();
    6. int a=curveColor.alpha();
    7.  
    8. QString role1=ui->btn_curveColor->windowRole();
    9.  
    10. cout<<"Use backgroundRole : r="<<r<<"\tg="<<g<<"\tb="<<b<<"\ta="<<a<<endl;
    11. cout<<"Use windowRole : "<<role1.toAscii().data()<<endl;
    To copy to clipboard, switch view to plain text mode 

    I get :
    Qt Code:
    1. Use backgroundRole : r=236 g=233 b=216 a=255
    2. Use windowRole :
    To copy to clipboard, switch view to plain text mode 

    in debug mode. i check the value of role is Button(1), and the role1 is a empty string.

    help me please.

    Micky Jhon




    Quote Originally Posted by anda_skoa View Post
    Have you tried the Background or Window roles?

    Cheers,
    _

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Get background color of QPushbutton

    Seems the style sheet does not change the palette but somehow overrides it.

    Too bad, seems you have to parse the stylesheet string yourself.

    Cheers,
    _

  5. #4
    Join Date
    Jan 2014
    Posts
    16
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Get background color of QPushbutton

    hi, anda_skoa.thank you all the same. i have to set the flat and AutoFillBackground attributes to true .so i get the result as i except.

    code is :
    Qt Code:
    1. ui->setupUi(this);
    2. ui->btn_curveColor->setFlat(true);
    3. ui->btn_curveColor->setAutoFillBackground(true);
    4. curveColor=ui->btn_curveColor->palette().color(QPalette::Button);
    5.  
    6. int r=curveColor.red();
    7. int g=curveColor.green();
    8. int b=curveColor.blue();
    9. int a=curveColor.alpha();
    10.  
    11. cout<<"r="<<r<<"\tg="<<g<<"\tb="<<b<<"\ta="<<a<<endl;
    To copy to clipboard, switch view to plain text mode 

    best wishes.

    Micky Jhon



    Quote Originally Posted by anda_skoa View Post
    Seems the style sheet does not change the palette but somehow overrides it.

    Too bad, seems you have to parse the stylesheet string yourself.

    Cheers,
    _

Similar Threads

  1. Change background color of QPushButton
    By gtthang in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2013, 10:23
  2. QPushbutton, background-color but flat ?
    By gab74 in forum Qt Programming
    Replies: 4
    Last Post: 15th December 2011, 10:15
  3. Background Color of QToolButton or QPushButton
    By metdos in forum Qt Programming
    Replies: 5
    Last Post: 17th June 2010, 11:02
  4. QPushButton color and background
    By satanowicz in forum Newbie
    Replies: 4
    Last Post: 25th May 2010, 20:56
  5. QPushbutton background color
    By omega36 in forum Qt Programming
    Replies: 27
    Last Post: 31st October 2008, 12:47

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.