1

So i trying to do paint and i run into some problems. When i try to draw QGraphicsRectItem it doesnt get positioned where i want it.

QColor neki1(23, 145, 195);
QPen pen1(neki1, 2, Qt::DashLine, Qt::RoundCap, Qt::RoundJoin);
QGraphicsRectItem* sel = new QGraphicsRectItem(0,0,100,100);
sel->setPen(pen1);
sel->setBrush(Qt::transparent);
addItem(sel);

enter image description here

this is the code and picture and you can see it get position like somewhere in the middle of the screen. On the begining of the program i set scene->setSceneRect(QRectF(0, 0, 1000, 1000)); but cordinates in top left corner of scene are not 0,0. Is there anyway to solve this?

Thank you for your help.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Tim Retelj
  • 19
  • 1

1 Answers1

0

Oh, that's common mistake. You had set scene's bounding rect. But QGraphcsView can scroll about and zoom into that scene. It "aims" at top left corner of scene, so 0,0 is somewhere near middle. You have to match view to the scene's bounding rect, e.g. with setAlignment, fitInView, etc.

Swift - Friday Pie
  • 12,777
  • 2
  • 19
  • 42