[Qt-interest] For creating arbitrary shapes of pushbutton

Luca Ottaviano lottaviano at develer.com
Mon Apr 6 09:32:02 CEST 2009


Il giorno lun, 06/04/2009 alle 11.45 +0530, Sunil ha scritto:
> Hi,
> 
> I tried re-implementing showEvent, but it is not working for me.

Hi,
you're right, I apologise for my mistake. You should reimplement
paintEvent(), Qt won't let you paint over a widget anywhere else (unless
you paint over a pixmap and you blit the pixmap over the widget in
paintEvent()).

Your code in showEvent() seems ok, but probably you would need to call
QPushButton::paintEvent() as the first statement in
MyPaint::paintEvent(). Try with and without that to see the difference.


> 
> Find below my code
> 
> class MyPaint : public QPushButton
> {
>     Q_OBJECT
> 
>     public:
>         MyPaint(QWidget *parent = 0);
>     protected:
>        void showEvent(QShowEvent *e);
>     private slots:
>         void paintslot();
> };
> 
> void MyPaint::showEvent(QShowEvent *e)
> {
>     QPainter painter(this);
> 
>     painter.setRenderHint(QPainter::Antialiasing, true);
>     painter.setPen(QPen(Qt::black, 15, Qt::SolidLine, Qt::RoundCap,
> Qt::MiterJoin));
>     painter.setBrush(QBrush(Qt::blue, Qt::DiagCrossPattern));
>     painter.drawPie(80,80,400,240,60*16,270*16);
> }
> 
> MyPaint::MyPaint(QWidget *parent): QPushButton(parent)
> {
>     connect(this, SIGNAL(clicked()), this, SLOT(paintslot()));
> }
> 
> void MyPaint::paintslot()
> {
>     this->close();
> }
> 
> int main(int argc, char *argv[])
> {
>     QApplication a(argc, argv);
>     QWidget *widget = new QWidget;
> 
>     MyPaint *p = new MyPaint(widget);
>     widget->show();
> 
>     return a.exec();
> }
> 
> Can you please suggest if any changes are required.
> 
> If you have any other example, please send it to us.
> 
> Thanks and Regards,
> Sunil.


Best regards,
-- 
Ing. Luca Ottaviano - lottaviano at develer.com
Develer S.r.l. - http://www.develer.com/
.hardware .software .innovation
Tel.: +39 055 3986627 - ext.: 218




More information about the Qt-interest-old mailing list