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

QGraphicsItem subclass item, doubleclickevent must doubleclick twice to select the item



    1. GraphicsPolygonItem subclass of QGraphicsPolygonItem; GraphicsView subclass of QGraphicsView;

    2. There are two GraphicsPolygonItem items(we call them item-A item-B) in the scene(GraphicsView hold the scene);

    3. I can doubleclick to select one item(item-A), but when I doubleclick the other(item-B), it doing nothing. But, I doubleclick item-B once again, item-B will be selected. It means I have to doubleclick twice to switch and select the other item.

    4. I have debug it as, when I doubleclick the other item, it will not come into the GraphicsPolygonItem::mouseDoubleClickEvent(QGraphi csSceneMouseEvent *event). If I doubleclick twice, it will come into the function.

    here is the code: //GraphicsPolygonItem

    void GraphicsPolygonItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
    {
        /*here doing some thing for select item......*/
        //...
        QGraphicsPolygonItem::update();
        QGraphicsPolygonItem::mouseDoubleClickEvent(event);
    }
    

    //GraphicsView

    void GraphicView::mouseDoubleClickEvent(QMouseEvent *event)
    {
        QGraphicsView::mouseDoubleClickEvent(event);
    }
    

    Be expecting your response! Thanks!



  • @TK_HPU said in QGraphicsItem subclass item, doubleclickevent must doubleclick twice to select the item:

    this->QGraphicsPolygonItem::update();

    I'm not a C++ expert, but what is this intended to be/do? Don't you mean either this->update(); or QGraphicsPolygonItem::update();?


  • Lifetime Qt Champion

    @JonB or simply update() ... :)



  • @Christian-Ehrlicher
    What will this->QGraphicsPolygonItem::update(); do? I haven't seen a this->Class::function() written before?



  • @JonB Forget it. It just call QGraphicsPolygonItem::update();


  • Moderators

    @JonB said in QGraphicsItem subclass item, doubleclickevent must doubleclick twice to select the item:

    What will this->QGraphicsPolygonItem::update(); do?

    Exactly what is written - call the QGraphicsPolygonItem::update on this. Usually it's not needed to do calls over fully qualified names, though ... and as usual this-> is superfluous, this isn't dependent lookup in template code.

    @TK_HPU, if I were to guess you do something odd in a part of the code that you haven't shown. From what you posted there doesn't seems to be any reason for this behavior. Post some more of your program - the stuff before QGraphicsPolygonItem::update. I'd imagine something to be wrong there (or thereabout), as currently from what you show you just delegate to the base class ...


Log in to reply