QListWidget, get item position in list?
-
wrote on 18 Jan 2022, 10:54 last edited by
Is it possible to get the index or position of an item in the list? I've looked at QListWidget and QListWidgetItem, nothing obvious...
When I get the signal currentItemChanged I get the current and previous items as parameters, what I need to do is store a reference to the position of each.
-
wrote on 18 Jan 2022, 11:03 last edited by JonB
@SPlatten
I don't see how int QListWidget::row(const QListWidgetItem *item) const does not give you that; if it isn't, I don't know what you are asking. But I leave it to you. -
Is it possible to get the index or position of an item in the list? I've looked at QListWidget and QListWidgetItem, nothing obvious...
When I get the signal currentItemChanged I get the current and previous items as parameters, what I need to do is store a reference to the position of each.
-
wrote on 18 Jan 2022, 10:56 last edited by
@JonB , I don't think so, this is a different question, just found this:
https://stackoverflow.com/questions/37601672/how-can-i-get-the-indices-of-qlistwidgetselecteditems -
@JonB , I don't think so, this is a different question, just found this:
https://stackoverflow.com/questions/37601672/how-can-i-get-the-indices-of-qlistwidgetselecteditemswrote on 18 Jan 2022, 10:58 last edited by JonB@SPlatten
I wrote:QListWidgetItem::listWidget()->row(item).
However, you may be safer using
QListWidgetItem::listWidget()->findItems(item->text())
, instead of relying on indexes staying the same, depending on what you are doing.How does
QListWidgetItem::listWidget()->row(item)
not answer your question, "position of an item in the list"? -
@SPlatten
I wrote:QListWidgetItem::listWidget()->row(item).
However, you may be safer using
QListWidgetItem::listWidget()->findItems(item->text())
, instead of relying on indexes staying the same, depending on what you are doing.How does
QListWidgetItem::listWidget()->row(item)
not answer your question, "position of an item in the list"? -
wrote on 18 Jan 2022, 11:03 last edited by JonB
@SPlatten
I don't see how int QListWidget::row(const QListWidgetItem *item) const does not give you that; if it isn't, I don't know what you are asking. But I leave it to you. -
@SPlatten
I don't see how int QListWidget::row(const QListWidgetItem *item) const does not give you that; if it isn't, I don't know what you are asking. But I leave it to you.
1/7