PDA

View Full Version : QGraphicsItem-QGraphicsScene



hgedek
4th August 2007, 12:23
I created a form using QGraphics classes.On them there are pictures.How can I scale them by using keyboard ?
(For scaling I am using QTimeLine class -scale() function etc.)

marcel
4th August 2007, 12:41
If you want to scale only the selected image( that item has to have the selectable flag ), independently of the other images, then you can catch keyboard event with QGraphicsItem::keyPressEvent.

If you want to scale the entire scene at the same time, then you can catch key presses with QGraphicsScene::keyPressEvent.

Please note that you have to subclass QGraphicsItem/QGraphicsScene and override keyPressEvent in order to be able to get key presses.

Regards

hgedek
4th August 2007, 12:49
I think I will use QGraphicsItem.On scene I have 6 image.And using keyboard I will pass one to another.Then pressed anothet button I will activate it.(Like Nokia menu!)

marcel
4th August 2007, 12:54
:)
To move with the keyboard from one item to another in a scene you will have to override QGraphicsScene::keyPressEvent and catch the arrow key presses there.
The default behavior for the arrow keys is none( the view will scroll actually ).

Regards

hgedek
4th August 2007, 13:27
Ok.I read scene::keyPressEvent.But I couldnt understand how to do.setFocus or setFocusItem
functions are used?Or how to do?

infos:
items are scaling translating etc in its Item class.This works by hover event.

marcel
4th August 2007, 13:35
I think QGraphicsItem::setSelected(true) should do it.
But, anyway, if the next item that you select does not have focus, you also should call setFocusItem. Make sure that all the items have the flags: ItemIsSelectable and ItemIsFocusable.

Regards