PDA

View Full Version : Why drawRect() has different display?



stella1016
13th April 2011, 15:48
With code1, the display looks very fine.

void my_graphics_view::resizeEvent(QResizeEvent *event)
{
setWidth(event->size().width());
setHeight(event->size().height());

fitInView(QRectF(0,0,width(),height()),Qt::KeepAsp ectRatioByExpanding);
arrangeNodes();

update();
}

void my_graphics_item::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
{
Q_UNUSED(option);

painter->setRenderHint(QPainter::SmoothPixmapTransform);
painter->setPen(QPen(Qt::red));
painter->setBrush(QBrush(Qt::gray, Qt::Dense4Pattern));

painter->drawRect(draw);
}

But with the following code2, the display changes:

void my_graphics_view::resizeEvent(QResizeEvent *event)
{
setWidth(event->size().width());
setHeight(event->size().height());

arrangeNodes();
m_scene->setSceneRect(0,0,width(),height());

update();
}

void my_graphics_item::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
{
Q_UNUSED(option);

painter->setRenderHint(QPainter::SmoothPixmapTransform);
painter->setPen(QPen(Qt::red));
painter->setBrush(QBrush(Qt::gray, Qt::Dense4Pattern));

painter->drawRect(draw);
}

This display of code1 and code2:

http://s1.postimage.org/2u9xd272c/diff.jpg (http://postimage.org/image/2u9xd272c/)