I have a QGraphicsRectItem. In its paint() method:
painter
->setPen
(QPen(Qt
::red,
1, Qt
::SolidLine));
painter
->setBrush
(QBrush(Qt
::gray, Qt
::Dense4Pattern));
painter->drawRect(draw_rect);
painter->setPen(QPen(Qt::red, 1, Qt::SolidLine));
painter->setBrush(QBrush(Qt::gray, Qt::Dense4Pattern));
painter->drawRect(draw_rect);
To copy to clipboard, switch view to plain text mode
QRectF Myclass
::boundingRect() const {
qreal adjust = 1.0;
QRectF result
(m_rect.
topLeft().
rx() - adjust
/2, m_rect.
topLeft().
ry() - adjust
/2,
m_rect.width() + adjust, m_rect.height() + adjust);
return result;
}
QRectF Myclass::boundingRect() const
{
qreal adjust = 1.0;
QRectF result(m_rect.topLeft().rx() - adjust/2, m_rect.topLeft().ry() - adjust/2,
m_rect.width() + adjust, m_rect.height() + adjust);
return result;
}
To copy to clipboard, switch view to plain text mode
Most of the time, the rectangle is painted correctly. But after resize, sometimes it will miss the red line boarder, for example the left-side edge is not painted.
I tried with following: doesn't work:
QRectF Myclass
::boundingRect() const {
qreal adjust = 1.0;
QRectF result
(m_rect.
topLeft().
rx() - adjust, m_rect.
topLeft().
ry() - adjust,
m_rect.width() + adjust, m_rect.height() + adjust);
return result;
}
QRectF Myclass::boundingRect() const
{
qreal adjust = 1.0;
QRectF result(m_rect.topLeft().rx() - adjust, m_rect.topLeft().ry() - adjust,
m_rect.width() + adjust, m_rect.height() + adjust);
return result;
}
To copy to clipboard, switch view to plain text mode
Any one know this problem?
Bookmarks