Good day. Tell me please, I have several rectangles on my stage (QGraphicsScene) (QGraphicsRectItem). I select them (set the corresponding flag in QGraphicsView), and how can I change the color of selected objects (I know how to get pointers to selected objects, but I don’t know how to fill in) or by pressing a button or by clicking on a selected area (the color is still not important, I would like to understand the process of flooding the selected area)

    1 answer 1

    In the QAbstractGraphicsShapeItem class, whose successor is your QGraphicsRectItem , there is a brush property, that is, a brush. Here it is used to fill the object. You can set a brush using the QAbstractGraphicsShapeItem :: setBrush method .

    To get the selected objects, you can use the QGraphicsScene::selectedItems method, which returns a list of selected objects. You can use the QGraphicsScene::selectionChanged signal to handle events that a selection has occurred.

    In sum, it turns out something like this:

     void SceneManager::OnConnectionChanged() { for(auto item : Scene.selectedItems()) { item->setBrush(SelectedBrush); } } 
    • Thank. I know this, in principle, my main problem is that I don’t know how to fill the selected area (that is, the selected elements that can accept the selection) - Yuri Ostroukh