PDA

View Full Version : QGraphicsScene item positioning



been_1990
27th July 2009, 22:06
How do I mange QGraphicsScene's items position? Everytime I add a new item on my scene it gets centralized.Why does it do that?

Lykurg
27th July 2009, 22:17
How do I mange QGraphicsScene's items position?
use QGraphicsItem::setPos()

Everytime I add a new item on my scene it gets centralized.Why does it do that?
The item must be positioned anywhere, but that's no problem where since you have to arrange the items in the screen by yourself using the above mentioned function.

been_1990
28th July 2009, 05:37
This is how I'm adding the pixmap:


scene->addItem(new QGraphicsPixmapItem(tempIcon.pixmap(100,QIcon::Nor mal,QIcon::On)));
How do I set its position if there was no name given to the QGraphicsPixmapItem?

nish
28th July 2009, 06:01
you have to save the item in a member pointer or other global pointer... ther are other ways like findItem but that would be unecessary slow

navi1084
28th July 2009, 06:01
you can rewrite this in following way:

QGrphicsPixmapItem* item = new QGraphicsPixmapItem(tempIcon.pixmap(100,QIcon::Nor mal,QIcon::On);
item->setPos(100, 100);
scene->addItem(item);

been_1990
28th July 2009, 11:45
Wont things mess up if I continually call a function with

QGrphicsPixmapItem* item = new QGraphicsPixmapItem(tempIcon.pixmap(100,QIcon::Nor mal,QIcon::On);
item->setPos(100, 100);
scene->addItem(item);
?

Lykurg
28th July 2009, 11:48
Wont things mess up if I continually call a function with

QGrphicsPixmapItem* item = new QGraphicsPixmapItem(tempIcon.pixmap(100,QIcon::Nor mal,QIcon::On);
item->setPos(100, 100);
scene->addItem(item);
?Yes of course, but as said, you have to take care yourself for the arrangement of the items in the scene. (Or you could use QGraphicsLinearLayout)

been_1990
28th July 2009, 13:11
Does QGraphicsLinearLayout automatically arrange the QGraphicsScene items in rows? Like

0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
If it does, how do I implement it? Do I just add the scenes items to a QGraphicLinear layout? Does it also modify the height and width of the item if requested?