Qt-interest Archive, March 2002
Painting a button
Message 1 in thread
Hi,
I would like to be able to change buttons to various colors at various times
in my program. I am however unsuccessful in this so far and would appreciate
any pointers.
Here's some code with various attempts to do something:
QPainter painter;
QPen pen(QColor(255,0,0), 8);
painter.begin(button);
painter.setPen(pen);
painter.setBackgroundColor(QColor(255,0,0));
painter.drawRect(0,0, 200, 200);
painter.drawPoint(1,1);
painter.end();
Nothing happens. Suspect I may be missing something vital. Can anyone help?
Thanks,
Sheena Ritchie
mail:sheena@mve.com
Message 2 in thread
Hello,
After you changed the painting color, you have to repaint()
it manually, because Qt would not be notified about it.
Using QPalette may be commom in your case, I think.
QWidget::setPalette() will take care much.
QPushButton* btn = new QPushButton(aWidget);
QPalette p(btn->palette());
p.setColor (QPalette::Normal,QColorGroup::Button,Qt::red);
btn->setPalette(a);
Naoyuki
On 2002 March 21 Thursday 20:39, Sheena Ritchie wrote:
> Hi,
> I would like to be able to change buttons to various
> colors at various times in my program. I am however
> unsuccessful in this so far and would appreciate any
> pointers.
> Here's some code with various attempts to do something:
>
> QPainter painter;
> QPen pen(QColor(255,0,0), 8);
> painter.begin(button);
> painter.setPen(pen);
> painter.setBackgroundColor(QColor(255,0,0));
> painter.drawRect(0,0, 200, 200);
> painter.drawPoint(1,1);
> painter.end();
>
> Nothing happens. Suspect I may be missing something
> vital. Can anyone help? Thanks,
> Sheena Ritchie
> mail:sheena@mve.com