PDA

View Full Version : How to set button's color



John-P
7th December 2009, 11:42
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.



palette = new QPalette();
palette->setColor(QPalette::Button , QColor(0,0,0,0) );
pushButton = new QPushButton(centralwidget);
pushButton->setPalette(QPalette(palette));
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(80, 220, 140, 140);
pushButton->setIcon(QIcon(QPixmap("icon.png")));
pushButton->setIconSize(QSize(140 , 140));



regards
John

Ginsengelf
7th December 2009, 11:51
Hi, QPalette takes a const reference, but you try to pass a pointer.
Use
pushButton->setPalette(*palette);
or first read the palette from the button, change it and then write it back (see QWidget::palette-prop (http://doc.trolltech.com/latest/qwidget.html#palette-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