Results 1 to 5 of 5

Thread: QPushbutton, background-color but flat ?

  1. #1
    Join Date
    Sep 2011
    Posts
    51
    Thanks
    2
    Qt products
    Qt4

    Default QPushbutton, background-color but flat ?

    I've a QPushBUtton

    i want to change the button color so i use a simple stylesheet

    setStyleSheet("QPushButton { background-color: red; color: black;}");

    The button is now red and text black, but it is became FLAT !!! So no, border and simple 3d effect like the standard button..

    Why this ?

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPushbutton, background-color but flat ?

    why? because that is what you told it to do.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPushbutton, background-color but flat ?

    For QPushButton, changing the background , you will need to change other properties as well.
    Usually QPushButton paints according to the system theme. You will need to use some image with 3D effect for the button to look better.

    Also there are ways to change colors of button using custom button.

  4. #4
    Join Date
    Sep 2011
    Posts
    51
    Thanks
    2
    Qt products
    Qt4

    Default Re: QPushbutton, background-color but flat ?

    My problem is that i have a simple panel with a button grey, with default qt style,
    but if i simply change the background to make the button red, the button becomes red but it not seems to be a button because it becomes flat, it seems a text box !!

  5. #5
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPushbutton, background-color but flat ?

    Qt Code:
    1. QPushButton* pb = new QPushButton("Test", this);
    2. pb->setStyleSheet(
    3. "QPushButton {"
    4. "margin: 1px;"
    5. "border-color: #0c457e;"
    6. "border-style: outset;"
    7. "border-radius: 3px;"
    8. "border-width: 1px;"
    9. "color: black;"
    10. "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #2198c0, stop: 1 #0d5ca6);"
    11. "}"
    12. "QPushButton:pressed {"
    13. "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #0d5ca6, stop: 1 #2198c0);"
    14. "}"
    15. );
    To copy to clipboard, switch view to plain text mode 
    Change what you want to what you want but general idea is that you have to style the button yourself from scratch.

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 color and background
    By satanowicz in forum Newbie
    Replies: 4
    Last Post: 25th May 2010, 20:56
  3. Change QPushButton Background Color, Qt4.3
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2009, 07:14
  4. QPushbutton background color
    By omega36 in forum Qt Programming
    Replies: 27
    Last Post: 31st October 2008, 12:47
  5. Change background color for a QPushButton?
    By Harvey West in forum Qt Programming
    Replies: 6
    Last Post: 5th January 2007, 14:23

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.