PDA

View Full Version : can you draw over a pushbutton?



illuzioner
29th June 2007, 19:36
hi,

has anyone successfully, in its paintEvent, drawn over a QPushButton?


void MyButton::paintEvent(QPaintEvent *Event)
{
QPainter painter(this);
QPushButton::paintEvent(Event);

QRect buttonRect=rect();
painter.setBrush(QBrush(Qt::red,Qt::SolidPattern)) ;
painter.drawRoundRect(buttonRect,20,20);
painter.drawText(0,0,w,h, Qt::AlignRight | Qt::AlignVCenter,QString("Button"),&buttonRect);
}
the code after the QPushButton:: paintEvent(Event) doesn't seem to do anything.

now, take out line 4 and you can see that the code works. strange.

anybody know how to fix this? stylesheets won't work for me in this case.

thanks! -- lou

marcel
29th June 2007, 20:02
What happens if you initialize the painter after calling the base class version?

Regards

illuzioner
29th June 2007, 20:19
What happens if you initialize the painter after calling the base class version?

wow, that was it:D. this is a difference in qt4 from qt3 where i had no problems doing it this way.

Thanks for that!
lou

tanmayb
22nd August 2017, 15:19
Hi,
I am new to Qt. I am facing the problem. Can you please provide me your working code?

wysota
30th August 2017, 08:14
Simply switch lines #3 and #4 in the OP's code.