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. QGraphicsItem subclass item, doubleclickevent must doubleclick twice to select the item

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 757 Views
  • 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 Offline
    T Offline
    TK_HPU
    wrote on last edited by TK_HPU
    #1
    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!

    JonBJ 1 Reply Last reply
    0
    • T 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!

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @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 EhrlicherC 1 Reply Last reply
      0
      • JonBJ JonB

        @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 EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @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

        JonBJ 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

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

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

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

          T kshegunovK 2 Replies Last reply
          0
          • JonBJ JonB

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

            T Offline
            T Offline
            TK_HPU
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • JonBJ JonB

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

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

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

              • Login

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