Results 1 to 2 of 2

Thread: How to set button's color

  1. #1
    Join Date
    Dec 2009
    Posts
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question How to set button's color

    Hi

    I want to set the color of pushButton to transparent.
    (button background color)
    I tried using setColor() to change "QPalette::Button" .
    But following build error occured.


    " invalid conversion from 'QPalette*' to 'QRgb' "
    "initializing argument 1 of 'QColor::QColor(QRgb)' "

    How can I resolve this error.

    Qt Code:
    1. palette = new QPalette();
    2. palette->setColor(QPalette::Button , QColor(0,0,0,0) );
    3. pushButton = new QPushButton(centralwidget);
    4. pushButton->setPalette(QPalette(palette));
    5. pushButton->setObjectName(QString::fromUtf8("pushButton"));
    6. pushButton->setGeometry(80, 220, 140, 140);
    7. pushButton->setIcon(QIcon(QPixmap("icon.png")));
    8. pushButton->setIconSize(QSize(140 , 140));
    To copy to clipboard, switch view to plain text mode 


    regards
    John

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    509
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to set button's color

    Hi, QPalette takes a const reference, but you try to pass a pointer.
    Use
    Qt Code:
    1. pushButton->setPalette(*palette);
    To copy to clipboard, switch view to plain text mode 
    or first read the palette from the button, change it and then write it back (see QWidget:alette-prop). With this method you will preserve all the other palette settings of the button while your code uses a default QPalette with one adjusted value.

    Ginsengelf
    Last edited by Ginsengelf; 7th December 2009 at 11:53. Reason: spelling error

Similar Threads

  1. Using a QFrame as a color selection indicator
    By KShots in forum Qt Tools
    Replies: 8
    Last Post: 14th June 2011, 23:55
  2. QStandardItem color modification
    By prashant in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2009, 09:24
  3. Display Label Color by selecting Color Picker
    By sosanjay in forum Qt Programming
    Replies: 1
    Last Post: 25th September 2009, 06:11
  4. button background color when it is clicked
    By navi1084 in forum Qt Programming
    Replies: 4
    Last Post: 9th December 2008, 15:02
  5. why do buttons don't change color?
    By Raccoon29 in forum Qt Programming
    Replies: 9
    Last Post: 16th November 2007, 12:00

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.