[Qt-interest] widget with round corners
Markus Franke
markus.franke at informatik.tu-chemnitz.de
Tue Feb 17 13:43:42 CET 2009
Zitat von Puneet Bisht <pbisht at nivio.com>:
> i want to do it in widgets init()
I guess you mean in the paintEvent() handler.
> can u explain it more.
Basically you have to create your own custom widget by creating an
instance of class QWidget. There you reimplement the paintEvent()
handler. In the constructor of your widget you're creating all the
stuff you need and then call update(). This will invoke your
paintEvent() method. There you simply draw with a QPainter object into
a pixmap and thereafter you draw this pixmap into your widget like the
following snippet:
---snip---
QPixmap image;
QPainter BgndPainter(&image);
/* do some drawing */
BgndPainter.end();
QPainter Painter(this);
Painter.drawPixmap(0, 0, image);
---snap---
It might be also possible to draw directly into the canvas of the
widget but I think the double buffered version above works more
performant with QT3.
Please correct anybody me if I am wrong. Hope this helps.
So long,
Markus
>> Zitat von Puneet Bisht <pbisht at nivio.com>:
>>
>>> i want to cut the extra region on the corners.
>>> can someone help me on this.
>>
>> Well, Qt4 provides style-sheets to achieve this. If it's a QLabel you
>> can simply set "border-radius" to some value. Don't know if this is
>> also possible with Qt3 but I am afraid it isn't. You can also paint
>> the widget by yourself in the widget's paintEvent() handler using
>> primives like drawRoundRect().
>>
>> So long,
>> Markus
>>
>>
>
>
>
More information about the Qt-interest-old
mailing list