[Qt-interest] Drawing a rect around a QCheckBox

Malyushytsky, Alex alex at wai.com
Thu Sep 17 00:57:57 CEST 2009


My guess is the order of operation.
Your drawing occurs BEFORE checkbox paint event.
So checkbox might paint over your rectangle.

I think you should to find a way to paint your rectangle AFTER Checkbox paint iself.
This might be either:
-  filter out paint event completely, draw Check box yourself before drawing the rectangle in your event handler;
-  Subclass checkbox, override paintEvent and do drawing of the rectangle there right after the call to QCheckBox: paintEvent;
-  create custom event and call PostEvent  in your message handler. This event will be delivered AFTER checkbox is processed and you can draw your rectangle there.


Regards Alex

-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Giacomo
Sent: Wednesday, September 16, 2009 4:23 AM
To: Ulf-Alexander v. Ceumern-Lindenstjerna
Cc: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Drawing a rect around a QCheckBox

On Wednesday 16 September 2009 12:09:33 you wrote:
> Hi Giacomo.
>
> What happens exactly? Is the code executed? Does the rect have the
> correct position and size?


Hi, thanks.

Yes, the code is executed,
A qDebug() prints the correct rectangle:

qDebug() << "widget rect: " << d_widget->rect(); /* see the code below */

The code is inside a objectFilter whose event() method intercepts
QEvent::Paint.

The code draws correctly the rectangle for QPushButtons, QLabels, QLineEdits,
and other custom QWidgets on which the same event filter is installed.

> Is the checkbox maybe drawn on top of the rect?

What does this mean? Maybe yes, I don't know. What I am sure is that
I call installEventFIlter on the checkbox and that event filter intercepts
QEvent::Paint

Thanks

>
> Regards, Ulf
>
> > -----Original Message-----
> > From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> > bounces at trolltech.com] On Behalf Of Giacomo
> > Sent: Wednesday, September 16, 2009 11:11 AM
> > To: qt-interest at trolltech.com
> > Subject: [Qt-interest] Drawing a rect around a QCheckBox
> >
> > Hi to all!
> >
> > I want to draw a rect around a QCheckbox.
> >
> > The code is as follows
> >
> > else if(event->type() == QEvent::Paint) /* inside a paint event */
> >   {
> >     QPaintEvent *paintEvent = static_cast<QPaintEvent*> (event);
> >
> >     if(paintEvent)
> >     {
> >       QPainter painter(d_widget); /* d_widget is a checkbox */
> >       qDebug() << "widget rect: " << d_widget->rect();
> >       QColor color = Qt::blue;
> >       QPen pen(color);
> >       pen.setWidth(2);
> >       painter.setPen(pen);
> >       QRect r = d_widget->rect();
> >       painter.drawRect(r)
> >       return false;/* do not filter out the event */
> >     }
> >   }
> >
> > While the code works fine on all other widgets i apply it (push
> > buttons,
> > QLabels...) in the checkbox no way.
> >
> > Thanks for any hint.
> >
> > Giacomo.
> >
> > ing. Giacomo Strangolino
> > Elettra - Synchrotron Radiation Facility - Trieste, Italy
> >
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
>
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

"Please consider our environment before printing this email."




More information about the Qt-interest-old mailing list