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. QListWidget, prompt before currentItemChanged signal
Forum Updated to NodeBB v4.3 + New Features

QListWidget, prompt before currentItemChanged signal

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 3 Posters 975 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.
  • SPlattenS SPlatten

    @jsulm

        class clsQtAskBeforeChange : public QItemSelectionModel {
        Q_OBJECT
        Q_DISABLE_COPY_MOVE(clsQtAskBeforeChange)
        public:
            using QItemSelectionModel::QItemSelectionModel;        
            QModelIndexList mobjLastIdxList;
    
        public slots:
            void select(const QItemSelection& crobjSelection
                       ,QItemSelectionModel::SelectionFlags flgsCmd) override {
                QModelIndexList objIdxList(crobjSelection.indexes());
                if ( mobjLastIdxList == objIdxList ) {
                    return;
                }
                mobjLastIdxList = objIdxList;
                emit pendingSelect(crobjSelection, flgsCmd);
            }
            virtual void actuallySelect(const QItemSelection& crobjSelection
                                       ,QItemSelectionModel::SelectionFlags flgsCmd) {
                QItemSelectionModel::select(crobjSelection, flgsCmd);
            }
    
        signals:
            void pendingSelect(const QItemSelection& crobjSelection
                              ,QItemSelectionModel::SelectionFlags flgsCmd);
        };
    

    After posting this I though it might be the check:

    if ( mobjLastIdxList == objIdxList ) {
        return;
    }
    

    Causing it to return, but it isn't.

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by jsulm
    #4

    @SPlatten Is the select() slot called?

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    SPlattenS 1 Reply Last reply
    0
    • jsulmJ jsulm

      @SPlatten Is the select() slot called?

      SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by
      #5

      @jsulm, as far as I can see with a breakpoint on the first line in the select function, no it isn't.

      Kind Regards,
      Sy

      jsulmJ 1 Reply Last reply
      0
      • SPlattenS SPlatten

        @jsulm, as far as I can see with a breakpoint on the first line in the select function, no it isn't.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #6

        @SPlatten Well, then find out why not.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        SPlattenS 1 Reply Last reply
        1
        • jsulmJ jsulm

          @SPlatten Well, then find out why not.

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #7

          @jsulm , that's exactly why I posted here, how ?

          Kind Regards,
          Sy

          jsulmJ 1 Reply Last reply
          0
          • SPlattenS SPlatten

            @jsulm , that's exactly why I posted here, how ?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #8

            @SPlatten How should I know?!
            You did not even tell us to what signal select() is connected!

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            SPlattenS 1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #9

              There are two select functions, the second is mostly called from QAbstractItemView

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

              SPlattenS 1 Reply Last reply
              0
              • jsulmJ jsulm

                @SPlatten How should I know?!
                You did not even tell us to what signal select() is connected!

                SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #10

                @jsulm , I'm not asking out specifically....looking at the class, its derived from QItemSelectionModel:
                https://doc.qt.io/qt-5/qitemselectionmodel.html#signals

                Kind Regards,
                Sy

                jsulmJ 1 Reply Last reply
                0
                • SPlattenS SPlatten

                  @jsulm , I'm not asking out specifically....looking at the class, its derived from QItemSelectionModel:
                  https://doc.qt.io/qt-5/qitemselectionmodel.html#signals

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #11

                  @SPlatten said in QListWidget, prompt before currentItemChanged signal:

                  QItemSelectionModel

                  OK, did not notice this

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    There are two select functions, the second is mostly called from QAbstractItemView

                    SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by
                    #12

                    @Christian-Ehrlicher , thank you, I can see that the select slot is getting called, but it appears that it is being called after the currentItemChanged signal, which is wrong isn't it?

                    Kind Regards,
                    Sy

                    Christian EhrlicherC 1 Reply Last reply
                    0
                    • SPlattenS SPlatten

                      @Christian-Ehrlicher , thank you, I can see that the select slot is getting called, but it appears that it is being called after the currentItemChanged signal, which is wrong isn't it?

                      Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      @SPlatten said in QListWidget, prompt before currentItemChanged signal:

                      which is wrong isn't it?

                      Why? Is it written down somewhere? And from my pov a cell has to be the current one until the selection can change.

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

                      SPlattenS 2 Replies Last reply
                      0
                      • Christian EhrlicherC Christian Ehrlicher

                        @SPlatten said in QListWidget, prompt before currentItemChanged signal:

                        which is wrong isn't it?

                        Why? Is it written down somewhere? And from my pov a cell has to be the current one until the selection can change.

                        SPlattenS Offline
                        SPlattenS Offline
                        SPlatten
                        wrote on last edited by
                        #14

                        @Christian-Ehrlicher , the intention is that when the user tries to make a new selection, an interim step checks that its ok to allow the change, by checking other content using the slot...it can then allow or disallow the selection.

                        Kind Regards,
                        Sy

                        1 Reply Last reply
                        0
                        • Christian EhrlicherC Christian Ehrlicher

                          @SPlatten said in QListWidget, prompt before currentItemChanged signal:

                          which is wrong isn't it?

                          Why? Is it written down somewhere? And from my pov a cell has to be the current one until the selection can change.

                          SPlattenS Offline
                          SPlattenS Offline
                          SPlatten
                          wrote on last edited by
                          #15

                          @Christian-Ehrlicher , @jsulm , I think I've been going down a rabbit hole in trying to implement this model, when all I actually need to do is move the test for change into the slot and then if I don't want to allow the selection change assign QListWidgetItem* pobjCurrent to QListWidgetItem* pobjPrevious.

                          Kind Regards,
                          Sy

                          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