[Qt-interest] Drawing a rect around a QCheckBox

Giacomo giacomo.strangolino at elettra.trieste.it
Wed Sep 16 11:11:18 CEST 2009


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




More information about the Qt-interest-old mailing list