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. Problem with delegates: repeated editing of same cell in QTableWidget has delay of ca 1 second
QtWS25 Last Chance

Problem with delegates: repeated editing of same cell in QTableWidget has delay of ca 1 second

Scheduled Pinned Locked Moved Solved General and Desktop
qtablewidgetdelegateeditingdelayslow
14 Posts 4 Posters 4.5k 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 7 Feb 2018, 21:45 last edited by
    #2

    Hi and welcome to devnet,

    What distribution/version of your OS are you using ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • L Offline
      L Offline
      linuxbastler
      wrote on 8 Feb 2018, 08:31 last edited by
      #3

      Linux: Ubuntu 17.10 64 Bit and Ubuntu 14.04 32 Bit
      Windows: Windows 7 64 Bit

      1 Reply Last reply
      0
      • V Offline
        V Offline
        VRonin
        wrote on 8 Feb 2018, 09:29 last edited by
        #4

        The problem is here basically it has to delay the editing because otherwise a double-click would be interpreted as 2 separate clicks.
        In release mode it's definetly not 1 sec but around 400ms

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        2
        • L linuxbastler
          7 Feb 2018, 09:15

          Problem can be reproduced with the "Star Delegate Example".

          1. open "Star Delegate Example"
          2. in main.cpp replace the EditTriggers with all EditTriggers to start editing with single mouse click:
            // tableWidget.setEditTriggers(QAbstractItemView::DoubleClicked
            // | QAbstractItemView::SelectedClicked);
            tableWidget.setEditTriggers(QAbstractItemView::AllEditTriggers);
          3. run the sample, click cell "Aqua" => editing starts immediately
          4. click cell "Tom Jones" => editing starts immediately
          5. click cell "Aqua" => editing starts immediately
          6. hit Escape-Key to leave cell "Aqua"
          7. click cell "Aqua" a second time => editing starts with a delay of ca 1 second

          We do not like this delay when consecutive editing the same cell. Where does this delay
          come from? Can it be disabled?
          This problem happens on Linux and Windows and on Qt 5.6.2 and Qt 5.10.

          J Offline
          J Offline
          JonB
          wrote on 8 Feb 2018, 09:51 last edited by JonB 2 Aug 2018, 09:51
          #5

          @linuxbastler, @VRonin

          As per @VRonin's reply, the Qt code resolves to:

          /*!
              \property QApplication::doubleClickInterval
              \brief the time limit in milliseconds that distinguishes a double click
              from two consecutive mouse clicks
              The default value on X11 is 400 milliseconds. On Windows and Mac OS, the
              operating system's value is used.
          */
          void QApplication::setDoubleClickInterval(int ms)
          {
              QGuiApplication::styleHints()->setMouseDoubleClickInterval(ms);
          }
          int QApplication::doubleClickInterval()
          {
              return QGuiApplication::styleHints()->mouseDoubleClickInterval();
          }
          

          So presumably if it really bothers you might do something about making your own call to QApplication::setDoubleClickInterval() to set it to a lower value. You might be able to do this just for the duration of your particular usage case, and have it restored to default the rest of the time.

          @VRonin
          One thing I do not see from your answer is the OP's:

          1. click cell "Aqua" => editing starts immediately
          2. hit Escape-Key to leave cell "Aqua"
          3. click cell "Aqua" a second time => editing starts with a delay of ca 1 second

          I don't see why the delay applies in #7 but not in #5?

          V 1 Reply Last reply 8 Feb 2018, 09:58
          0
          • J JonB
            8 Feb 2018, 09:51

            @linuxbastler, @VRonin

            As per @VRonin's reply, the Qt code resolves to:

            /*!
                \property QApplication::doubleClickInterval
                \brief the time limit in milliseconds that distinguishes a double click
                from two consecutive mouse clicks
                The default value on X11 is 400 milliseconds. On Windows and Mac OS, the
                operating system's value is used.
            */
            void QApplication::setDoubleClickInterval(int ms)
            {
                QGuiApplication::styleHints()->setMouseDoubleClickInterval(ms);
            }
            int QApplication::doubleClickInterval()
            {
                return QGuiApplication::styleHints()->mouseDoubleClickInterval();
            }
            

            So presumably if it really bothers you might do something about making your own call to QApplication::setDoubleClickInterval() to set it to a lower value. You might be able to do this just for the duration of your particular usage case, and have it restored to default the rest of the time.

            @VRonin
            One thing I do not see from your answer is the OP's:

            1. click cell "Aqua" => editing starts immediately
            2. hit Escape-Key to leave cell "Aqua"
            3. click cell "Aqua" a second time => editing starts with a delay of ca 1 second

            I don't see why the delay applies in #7 but not in #5?

            V Offline
            V Offline
            VRonin
            wrote on 8 Feb 2018, 09:58 last edited by VRonin 2 Aug 2018, 10:16
            #6

            @JonB said in Problem with delegates: repeated editing of same cell in QTableWidget has delay of ca 1 second:

            I don't see why the delay applies in #7 but not in #5?

            Because the delay only applies if (trigger == SelectedClicked)

            A possible solution for your problem is to subclass the view, reimplementing bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event) to change SelectedClicked to NoEditTrigger and call the base class

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            2
            • L Offline
              L Offline
              linuxbastler
              wrote on 8 Feb 2018, 12:39 last edited by
              #7

              @JonB
              VRonin is right, the delay only happens, if a selected cell is clicked to edit again.
              This is the differende of #7 to #5.

              @JonB
              the solution to use setDoubleClickInterval(int ms) works partially but not for everything in our program. E. g. with setDoubleClickInterval(0) the delay is gone, but Combo Boxes will open and close with one click (they then get a doubleclick?).

              So we tried to solution of @VRonin (subclass the view, reimplement edit).
              This works for us, but it is a little bit of software overhead to workaround the problem.

              @VRonin @JonB
              Seems there is some kind of "SingleClicked" missing in Qt to detect a single mouse click on a
              selected editable cell.
              We don't clearly see what a single click on a selected cell has to do with double clicks?

              Thanks for the solutions!

              V J 2 Replies Last reply 8 Feb 2018, 13:03
              0
              • L linuxbastler
                8 Feb 2018, 12:39

                @JonB
                VRonin is right, the delay only happens, if a selected cell is clicked to edit again.
                This is the differende of #7 to #5.

                @JonB
                the solution to use setDoubleClickInterval(int ms) works partially but not for everything in our program. E. g. with setDoubleClickInterval(0) the delay is gone, but Combo Boxes will open and close with one click (they then get a doubleclick?).

                So we tried to solution of @VRonin (subclass the view, reimplement edit).
                This works for us, but it is a little bit of software overhead to workaround the problem.

                @VRonin @JonB
                Seems there is some kind of "SingleClicked" missing in Qt to detect a single mouse click on a
                selected editable cell.
                We don't clearly see what a single click on a selected cell has to do with double clicks?

                Thanks for the solutions!

                V Offline
                V Offline
                VRonin
                wrote on 8 Feb 2018, 13:03 last edited by
                #8

                @linuxbastler said in Problem with delegates: repeated editing of same cell in QTableWidget has delay of ca 1 second:

                We don't clearly see what a single click on a selected cell has to do with double clicks?

                Say you have tableWidget.setEditTriggers(QAbstractItemView::SelectedClicked); and you have something like connect(&tableWidget,&QAbstractItemView::doubleClicked,[]()->void{qDebug("Double Clicked!");});

                instead of step 7, double-click on "Aqua". when you release the mouse and no delay is set, the editing starts, then you have a further mousepress+mouserelease that puts the cursor at the mouse position. This is not the expected behaviour, the correct one would be to execute the slot. Basically the problem is that at the time of the first mouserelease there is no way of knowing if the user intends to double-click or not so we have to wait and see

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                1 Reply Last reply
                1
                • L linuxbastler
                  8 Feb 2018, 12:39

                  @JonB
                  VRonin is right, the delay only happens, if a selected cell is clicked to edit again.
                  This is the differende of #7 to #5.

                  @JonB
                  the solution to use setDoubleClickInterval(int ms) works partially but not for everything in our program. E. g. with setDoubleClickInterval(0) the delay is gone, but Combo Boxes will open and close with one click (they then get a doubleclick?).

                  So we tried to solution of @VRonin (subclass the view, reimplement edit).
                  This works for us, but it is a little bit of software overhead to workaround the problem.

                  @VRonin @JonB
                  Seems there is some kind of "SingleClicked" missing in Qt to detect a single mouse click on a
                  selected editable cell.
                  We don't clearly see what a single click on a selected cell has to do with double clicks?

                  Thanks for the solutions!

                  J Offline
                  J Offline
                  JonB
                  wrote on 8 Feb 2018, 15:30 last edited by
                  #9

                  @linuxbastler
                  As @VRonin has explained above, every system does have to have some delay way of deciding whether a click is "standalone" or the start of a "double-click". And they have to do that by some delay after the first click to see if there is a second click coming. So they all have to do that, it's just a question of how long the delay is.

                  1 Reply Last reply
                  2
                  • L Offline
                    L Offline
                    linuxbastler
                    wrote on 12 Feb 2018, 07:36 last edited by
                    #10

                    we do not use doubleclick in this QTableWidget because we are on a touch device.
                    Would be nice to have some configuration / settings to configure doubleclick in this situation

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      VRonin
                      wrote on 12 Feb 2018, 08:35 last edited by VRonin 2 Dec 2018, 14:51
                      #11

                      If you don't use doubleclick then the "reimplement edit() in the view" solution is what you are after. You can actually make it a template to make it so you just need to change 1 line in your existing code:

                      template<class T>
                      class NoDelayView : public T{
                          #ifdef Q_COMPILER_STATIC_ASSERT
                          static_assert(std::is_base_of<QAbstractItemView,T>::value,"Template argument must be a QAbstractItemView");
                          #endif
                          Q_DISABLE_COPY(NoDelayView);
                      public:
                          explicit NoDelayView(QWidget* parent = Q_NULLPTR)
                              : T(parent)
                          {}
                      protected:
                          bool edit(const QModelIndex &index, QAbstractItemView::EditTrigger trigger, QEvent *event) Q_DECL_OVERRIDE{
                              return T::edit(index, trigger == QAbstractItemView::SelectedClicked ? QAbstractItemView::AllEditTriggers : trigger, event);
                          }
                      };
                      

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      1 Reply Last reply
                      4
                      • L Offline
                        L Offline
                        linuxbastler
                        wrote on 12 Feb 2018, 14:21 last edited by
                        #12

                        @VRonin
                        ok, we got the idea of subclassing the view and reimplementing bool edit().
                        This solution is working for us, thanks!
                        The template solution seems to be elegant but we did not get it running with the "Star Delegate Example" in the first try.

                        V 1 Reply Last reply 12 Feb 2018, 14:51
                        0
                        • L linuxbastler
                          12 Feb 2018, 14:21

                          @VRonin
                          ok, we got the idea of subclassing the view and reimplementing bool edit().
                          This solution is working for us, thanks!
                          The template solution seems to be elegant but we did not get it running with the "Star Delegate Example" in the first try.

                          V Offline
                          V Offline
                          VRonin
                          wrote on 12 Feb 2018, 14:51 last edited by VRonin 2 Dec 2018, 14:52
                          #13

                          @linuxbastler said in Problem with delegates: repeated editing of same cell in QTableWidget has delay of ca 1 second:

                          The template solution seems to be elegant but we did not get it running with the "Star Delegate Example" in the first try.

                          Fixed a few typos up there, now just replace QTableWidget tableWidget(4, 4); with

                          NoDelayView<QTableWidget> tableWidget;
                          tableWidget.setRowCount(4);
                          tableWidget.setColumnCount(4);
                          

                          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                          ~Napoleon Bonaparte

                          On a crusade to banish setIndexWidget() from the holy land of Qt

                          1 Reply Last reply
                          2
                          • L Offline
                            L Offline
                            linuxbastler
                            wrote on 12 Feb 2018, 15:19 last edited by
                            #14

                            ok, the template solution is also working here.
                            Thanks a lot for your help!

                            1 Reply Last reply
                            0

                            11/14

                            12 Feb 2018, 08:35

                            • Login

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