Painting outside widget geometry?
I have a QWidget that I am overriding the paintEvent method. The widget is basically a square with some "arms" . For the most part I want to be able to move this widget around using widget->move(x,y); But I added a new method to extend the "arms" of the widget. My problem is that the widget's size is the size of the rectangle I want to draw. And when I try to draw the "arms" they do not get drawn.
Here is my code in the paint event.
Code:
{
double dWidth = width();
double dHeight = height();
painter.
setRenderHint(QPainter::Antialiasing);
painter.save();
pen.setWidth(5);
painter.setPen(pen);
QRectF rect
(0.0,
0.0,dWidth,dHeight
);
painter.drawRect(rect);
pen.setColor(Qt::red);
painter.setPen(pen);
if ( m_nArmY < 0 )
{
QLineF arm1
(0.0,
0.0,
0.0,m_nArmY
);
QLineF arm2
(dWidth,
0.0,dWidth,m_nArmY
);
painter.drawLine(arm1);
painter.drawLine(arm2);
}
else
{
QLineF arm1
(0.0,dHeight,
0.0,m_nArmY
+ dHeight
);
QLineF arm2
(dWidth,dHeight,dWidth,m_nArmY
+ dHeight
);
painter.drawLine(arm1);
painter.drawLine(arm2);
}
painter.restore();
}
Re: Painting outside widget geometry?
The painter is clipped to the widget rectangle, so that you can't paint over other widgets, you shouldn't try to override it. You could create external widgets for your arms and set their background to be invisible and move those widgets along with the "main" widget.
Re: Painting outside widget geometry?
Thanks. That's what I figured the problem was. I'll try to create the arms the way you said, and see how that works.