[Qt-interest] Drawing a rect around a QCheckBox
Giacomo
giacomo.strangolino at elettra.trieste.it
Wed Sep 16 13:23:21 CEST 2009
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
>
More information about the Qt-interest-old
mailing list