SOLVED - Is myQListWidget->selectedItems().at(0)->text() always the same as myQListWidget->currentItem()->text() ?



  • Given, the mode of selection is single selection, do these both yield the same result?

    myQListWidget->selectedItems().at(0)->text();
    myQListWidget->currentItem()->text();


  • Lifetime Qt Champion

    Hi,

    AFAICT, yes. But to confirm that, writing a little test application would have got you the answer sooner



  • Thanks @SGaist! I am sorry, I wasn't able to find the official Qt repo at the time of posting this question, that's why I asked this question. Later, when I found it, I went through the code and got my answer.

    The answer is:
    If a QListWidgetItem is passed to setCurrentItem() (directly or indirectly; setCurrentItem() also selects the specified item, if the selection mode is notQAbstractItemView::NoSelection), then both myQListWidget->selectedItems().at(0)->text() and myQListWidget->currentItem()->text() show the same result. Whereas, if an item is selected by any other means, then it may or may not become the current item, hence both may yield different results.


  • Lifetime Qt Champion

    Why did you need the Qt repo ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.