{
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();
}
void MyWidget::paintEvent(QPaintEvent * event)
{
double dWidth = width();
double dHeight = height();
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.save();
QPen pen(Qt::black);
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();
}
To copy to clipboard, switch view to plain text mode
Bookmarks