How to select multiple items without pressing Ctrl key within QGraphicsScene?

后端 未结 2 1295
梦谈多话
梦谈多话 2021-02-06 16:59

In Qt\'s QGraphicsScene, if I wanna one item, just click it, and click another selectable item will make the selected item to be unselected. If I want to select mul

2条回答
  •  执笔经年
    2021-02-06 17:45

    maybe it's a hack but it's works for me. In this example you can select multiple items using shift key

    void MySceneView::mousePressEvent(QMouseEvent *event)
    {
        if (event->modifiers() & Qt::ShiftModifier ) //any other condition
            event->setModifiers(Qt::ControlModifier);
    
        QGraphicsView::mousePressEvent(event);
    }
    
    
    void MySceneView::mouseReleaseEvent(QMouseEvent *event)
    {
        if (event->modifiers() & Qt::ShiftModifier ) //any other condition
            event->setModifiers(Qt::ControlModifier);
    
        QGraphicsView::mouseReleaseEvent(event);
    }
    

提交回复
热议问题