cl0ne / resizer-item

A resizer QGraphicsItem.
Other
8 stars 4 forks source link

How Hide HandleItems of GraphicsItemResizer and show it when QGraphicsItem is selected. #5

Closed parisa-hr closed 3 years ago

parisa-hr commented 3 years ago

Hi I want to Resize my QGraphicsItem when it is selected , how can do this? I mean I want HandleItem 's squares to become hide and when the user selects one Item, they appear and user has resized access.

cl0ne commented 3 years ago

Hi!

I see (at least) two ways to accomplish what you want without modifying/inheriting from the GraphicsItemResizer:

Another option would be to use QGraphicsItem::installSceneEventFilter in the GraphicsItemResizer (or its subclass) to intercept selection events.

Hope this helps.

parisa-hr commented 3 years ago

Hi!

I see (at least) two ways to accomplish what you want without modifying/inheriting from the GraphicsItemResizer:

* Listen for [QGraphicsScene::selectionChanged](https://doc.qt.io/qt-5/qgraphicsscene.html#selectionChanged) and attach resizer to currently selected items, you have to track previously selected items though (to detach resizers from them);

* Listen for `ItemSelectedHasChanged` event in [QGraphicsItem::itemChange](https://doc.qt.io/qt-5/qgraphicsitem.html#itemChange) of the items to be selectable and detach/attach `GraphicsItemResizer` as the parent item to the corresponding item.

Another option would be to use QGraphicsItem::installSceneEventFilter in the GraphicsItemResizer (or its subclass) to intercept selection events.

Hope this helps.

Thanks.