PDA

View Full Version : why item corrdinate is incorrect inside QgraphicsScene?



hashb
8th September 2010, 11:14
Hi All,




view_ = new QGraphicsView(this);
qDebug()<<view_->horizontalScrollBar()->height(); //30

view_->resize(
200 + view_->horizontalScrollBar()->height(),
200+view_->horizontalScrollBar()->height()
);
scene_ = new QGraphicsScene(0,0,200,200,this);
view_->setScene(scene_);

QGraphicsRectItem *rect = new QGraphicsRectItem(QRect(0,0,20,20));
rect->setBrush(Qt::red);
rect->setPos(0,0);
scene_->addItem(rect);


QPushButton *bt=new QPushButton("ok",this);
bt->move(15,15);





since default alignment of scene is center,
and the view's size is (230,230)
the scene's size is (200,200)
so I guess ,the rect should at QPoint(15,15),
I place a button at QPoint(15,15) to check whether the button can cover the rect totally,
but from the attached pic ,we can see there is a gap between them ,
I was wondering why, any ideas about it?

Thank advance for your help.
Best regards,
hb