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. SOLVED - Is myQListWidget->selectedItems().at(0)->text() always the same as myQListWidget->currentItem()->text() ?

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.1k Views 2 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.
  • WingsW Offline
    WingsW Offline
    Wings
    wrote on last edited by Wings
    #1

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

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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • WingsW Offline
        WingsW Offline
        Wings
        wrote on last edited by Wings
        #3

        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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Why did you need the Qt repo ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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