[Qt-interest] QPalette
chandrasekar wagmare
sekarwagmare at gmail.com
Tue May 5 08:26:51 CEST 2009
i am sorry, i forward with wrong mail reply ...
On Tue, May 5, 2009 at 11:54 AM, chandrasekar wagmare <
sekarwagmare at gmail.com> wrote:
>
> pushButton = new QPushButton(this);
> QPixmap pixmap("file.png");
> pushButton->setIcon(QIcon(pixmap));
> pushButton->setIconSize(pixmap.size());
>
>
> On Tue, May 5, 2009 at 9:44 AM, Girish Ramakrishnan <girish at forwardbias.in
> > wrote:
>
>> Alvaro Sánchez wrote:
>> > Hi all,
>> >
>> > I'm trying to change the button color (no border) using the below
>> code:
>> >
>> > QPalette palette = ui.pushButton->palette();
>> > palette.setColor( QPalette::Normal, QPalette::Button, QColor(Qt::red)
>> );
>> > ui.pushButton->setPalette(palette);
>> >
>> >
>> >
>> > ui.pushButton->setAutoFillBackground(true);
>> >
>> > and the result is wrong, the pushButton border is red instead of the
>> > button, does anybody know how to resolve it?
>> >
>>
>> This cannot be resolved, read up the stylesheet documentation as to why.
>> http://doc.trolltech.com/4.5/stylesheet.html.
>>
>> > If I use QStyleSheet to define a "background-color: red" to apply the
>> > pushButton, the result is correct, but my memory grows up, does anybody
>> > know why is happening?
>> >
>> > #include "ui_testqt.h"
>> >
>> > class testqt : public QDialog
>> > {
>> > Q_OBJECT
>> >
>> > public:
>> > testqt(QWidget *parent = 0);
>> >
>> >
>> > void Refresh();
>> >
>> > private slots:
>> > void on_pushButton_pressed();
>> > void closeEvent (QCloseEvent *);
>> >
>> >
>> > private:
>> > Ui_Dialog ui;
>> >
>> > bool bStatus;
>> >
>> >
>> > };
>> >
>> >
>> > include "testqt.h"
>> >
>> > testqt::testqt(QWidget *parent)
>> > : QDialog(parent)
>> > {
>> > QString qtstylesheet = "background-color: yellow";
>> >
>> > ui.setupUi(this);
>> > bStatus = false;
>> > }
>> >
>> > void testqt::on_pushButton_pressed()
>> > {
>> > bStatus = !bStatus;
>> > }
>> >
>> > void testqt::Refresh()
>> > {
>> > QString qtstylesheet = "background-color: yellow";
>> > QString qtstylesheet2 = "background-color: red";
>> >
>> > if (bStatus)
>> > {
>> > ui.pushButton->setStyleSheet(qtstylesheet);
>> > }
>> > else
>> > {
>> > ui.pushButton->setStyleSheet(qtstylesheet2);
>> > }
>> >
>>
>> Seems complex. All you need is the following stylesheet:
>> setStyleSheet("QPushButton { background-color: yellow; }
>> QPushButton:pressed { background-color: red }");
>>
>> The correct usage is in the documentation above.
>>
>> Girish
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>
>
>
> --
> WAGMARE
>
--
WAGMARE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090505/0908d399/attachment.html
More information about the Qt-interest-old
mailing list