QListWidget, prompt before currentItemChanged signal
-
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?
-
@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.
@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.
-
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?
@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? -
@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?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.
-
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.
-
@jsulm, as far as I can see with a breakpoint on the first line in the select function, no it isn't.
-
-
@SPlatten How should I know?!
You did not even tell us to what signal select() is connected! -
@jsulm , I'm not asking out specifically....looking at the class, its derived from QItemSelectionModel:
https://doc.qt.io/qt-5/qitemselectionmodel.html#signals@SPlatten said in QListWidget, prompt before currentItemChanged signal:
QItemSelectionModel
OK, did not notice this
-
@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-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?
@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.
-
@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.
@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.
-
@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.
@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.