Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt GraphicsItem Resize handlers



  • Hi, this my first post here :)
    I am not expirienced programmer and I would like to make something like when I click on my custom graphic object it becomes selected and the resize handlers appears around the item i know how to do the resizing and all the hard stuff but i dont know how to send information to my resizer object (which contains the pointer to my custom item) that my custom item has been clicked and the handlers should appear. I dont want to use slots and signals because I want to have many (like 100+) objects.

    I know that i can override mouseevent in my customitem but how to pass the info about being clicked to resizehandlers

    MyCustomItem *item = new MyCustomItem(parent);
        scene->addItem(item);
        ResizerItem *reItem = new ResizerItem(item); 
        scene->addItem(reItem);
    

  • Moderators

    Hi, welcome to the forum.

    You can make the item selectable by setting the QGraphicsItem::ItemIsSelectable flag on it.

    As for signals/slots - you do need to use them, but not on individual items. You can connect to the selectionChanged() signal of the scene, and in the slot handling that you will get currently selected items with scene's selectedItems() method.

    As for passing the mouse events - you don't need to do that. The resize handles can be separate items that get mouse events, so you don't need to pass them from the selected item.


  • Moderators

    Hi, welcome to the forum.

    You can make the item selectable by setting the QGraphicsItem::ItemIsSelectable flag on it.

    As for signals/slots - you do need to use them, but not on individual items. You can connect to the selectionChanged() signal of the scene, and in the slot handling that you will get currently selected items with scene's selectedItems() method.

    As for passing the mouse events - you don't need to do that. The resize handles can be separate items that get mouse events, so you don't need to pass them from the selected item.



  • @Chris-Kawa Okay, Thank you very much for fast answer I think that I know how to do it now


Log in to reply