[Solved] QGraphicsView mousePressEvent and selection behavior?



  • Hi
    I'm new to Qt framework, I re implemented the mousePressEvent to place a custom item on the scene , but the problem is now, I can't select the items with single click, I can select it using only double click, I can't select a group by dragging the mouse to draw selection rectangle.

    should I implement all these functions again to make it work with single click?
    @void YPeersView::mousePressEvent(QMouseEvent event)
    {
    QPoint p=event->pos();
    QPointF pf=mapToScene(p);
    YPeerNode * node=NULL;
    switch(getPeersViewState())
    {
    case YCore::PeerScenarioStateAddNode:
    addNode(pf);
    break;
    case YCore::PeerScenarioStateAddConnection:
    break;
    case YCore::PeerScenarioStateRemove:
    break;
    case YCore::PeerScenarioStateSelect:
    node=(YPeerNode
    ) scene()->itemAt(mapToScene(event->pos()));
    if(node && node->isEnabled() && node->flags() & QGraphicsItem::ItemIsSelectable)
    node->setSelected(!node->isSelected());

        break;
    default:
        break;
    
    }
    

    QGraphicsView::event(event);
    }@

    I've sent the event to the parent but it's not working.



  • Should QGraphicsView::event(event) be instead QGraphicsView::mousePressEvent(event) in the case you want the default handler?

    -=ben



  • thank you
    You are right about it.
    I missed this this point, thank you.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.