QListWidget row and selection
-
Hello,
apparently, the currentRow() of a QListWidget is updated after its selection. So if I connect itemSelectionChanged() with a slot which calls currentRow(), the currentRow() function still returns the former selected row.
Is this a bug? Or is it working correctly and it's just me not understand the sense of it? -
What exactly do you want to achieve?
"QListWidget":http://qt-project.org/doc/qt-4.8/qlistwidget.html offers a variety of singals such as itemChanged, itemActivated, itemClicked and so on which should fit your needs.
-
use "void QListWidget::currentItemChanged ( QListWidgetItem * current, QListWidgetItem * previous )" instead of itemSelectionChanged(). it gives you the current and the previous item
-
Yes, I know how I could circumvent this issue but my question was whether this is a bug or intended by the developers. And if it's not a bug, why did they choose to do it that way?
-
Ok, nobody seems to know, so let me ask a slightly different question:
If a slot uses both currentRow() and selectedItems(), do I have to connect it with both corresponding signals to be assured that everything will be executed correctly?I saw this in the undo demo:
@ connect(doc->undoStack(), SIGNAL(indexChanged(int)), this, SLOT(updateActions()));
connect(doc->undoStack(), SIGNAL(cleanChanged(bool)), this, SLOT(updateActions()));@
The second line seems to be unnecessary but updateActions() calls doc-undoStack()->isClean(), which might give a wrong return value in the first "connect"-call.