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 974 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

    I thought I had this working...I add the following to QListWidget:

        QString strFunc(slstScript[SSF_FUNCTION_IDX]
                      + QString(clsDebugService::msccBrktOpen)
                      + QString(clsDebugService::msccBrktClose));
        QByteArray baScriptWithCall(clsMainWnd::baGetScriptWithCall(itr->second, strFunc));
        QJSEngine* pobjScriptEng(clsJSON::pobjGetScriptEng());
        //Use "clsQtAskBeforeChange" to prompt user for confirmation if
        //changes in child nodes before allowing change
        clsQtAskBeforeChange* pobjABC(new clsQtAskBeforeChange(model(), this));
        setSelectionMode(QAbstractItemView::ExtendedSelection);
        setSelectionModel(pobjABC);
        //Now the widget should be set-up, finalise set-up
        clsXMLinterface::setup();
        //Connect signal
        QObject::connect(pobjABC, &clsQtAskBeforeChange::pendingSelect
                ,this, [this, pobjABC, pobjScriptEng, strFile, strFunc, baScriptWithCall]
                        (const QItemSelection& crobjSelection
                        ,QItemSelectionModel::SelectionFlags cmdFlags) {
            bool blnBlock(this->blockSignals(true));
            QJSValue objResult(pobjScriptEng->evaluate(baScriptWithCall));
            this->blockSignals(blnBlock);
            if ( objResult.isError() == true ) {
                qcrt() << "\n*****************************************************************"
                       << "\n" << strFile << strFunc
                       << "\n" << objResult.toString()
                       << "\n*****************************************************************";
            } else {
                QString strResult(objResult.toString());
                if ( strResult.compare(clsXMLnode::mscszTrue) == 0 ) {
                    pobjABC->actuallySelect(crobjSelection, cmdFlags);
                } else if ( strResult.compare("undefined") != 0 ) {
                    qdbg() << "9" << clsDebugService::msccDebugLevelDelimiter
                                  << strResult.toLocal8Bit().data();//HACK
                }
            }
        });
    

    I have a breakpoint on the first line of the lambda slot:

    bool blnBlock(this->blockSignals(true));
    

    I have connections to all the signals and I see that when I make a selection from the list, it jumps directly into:

    void clsQtListWidget::rptrCurrentItemChanged(QListWidgetItem* pobjCurrent
                                                ,QListWidgetItem* pobjPrevious) {
    

    Which is connected to the signal currentItemChanged.

    Can anyone see why the pendingSelect select signal isn't occurring?

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

    @SPlatten said in QListWidget, prompt before currentItemChanged signal:

    Can anyone see why the pendingSelect select signal isn't occurring?

    How should anyone know?
    What is clsQtAskBeforeChange and when does it emit pendingSelect signal?

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

    SPlattenS 1 Reply Last reply
    1
    • jsulmJ jsulm

      @SPlatten said in QListWidget, prompt before currentItemChanged signal:

      Can anyone see why the pendingSelect select signal isn't occurring?

      How should anyone know?
      What is clsQtAskBeforeChange and when does it emit pendingSelect signal?

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

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

      Kind Regards,
      Sy

      jsulmJ 1 Reply Last reply
      0
      • 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