Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QGraphicsView mousePressEvent and selection behavior?
Forum Updated to NodeBB v4.3 + New Features

[Solved] QGraphicsView mousePressEvent and selection behavior?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 5.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maherali
    wrote on last edited by
    #1

    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.

    life is just lines of code

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mirswith
      wrote on last edited by
      #2

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

      -=ben

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maherali
        wrote on last edited by
        #3

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

        life is just lines of code

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved