Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    4
    6
    387
    Loading More Posts
    • 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.
    • T
      TK_HPU last edited by TK_HPU

      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!

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @TK_HPU last edited by

        @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();?

        Christian Ehrlicher 1 Reply Last reply Reply Quote 0
        • Christian Ehrlicher
          Christian Ehrlicher Lifetime Qt Champion @JonB last edited by

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

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          JonB 1 Reply Last reply Reply Quote 0
          • JonB
            JonB @Christian Ehrlicher last edited by

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

            T kshegunov 2 Replies Last reply Reply Quote 0
            • T
              TK_HPU @JonB last edited by

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

              1 Reply Last reply Reply Quote 0
              • kshegunov
                kshegunov Moderators @JonB last edited by

                @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 ...

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply Reply Quote 3
                • First post
                  Last post