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. QListWidget, get item position in list?
QtWS25 Last Chance

QListWidget, get item position in list?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 5.8k Views
  • 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.
  • S Offline
    S Offline
    SPlatten
    wrote on 18 Jan 2022, 10:54 last edited by
    #1

    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.

    Kind Regards,
    Sy

    J 1 Reply Last reply 18 Jan 2022, 10:56
    0
    • S SPlatten
      18 Jan 2022, 11:00

      @JonB , that's not the same. Now it's now just the item but its position in the list.

      J Online
      J Online
      JonB
      wrote on 18 Jan 2022, 11:03 last edited by JonB
      #6

      @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.

      S 1 Reply Last reply 18 Jan 2022, 11:06
      3
      • S SPlatten
        18 Jan 2022, 10:54

        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.

        J Online
        J Online
        JonB
        wrote on 18 Jan 2022, 10:56 last edited by
        #2

        @SPlatten
        Did I not answer just this in your other post??

        S 1 Reply Last reply 18 Jan 2022, 10:56
        0
        • J JonB
          18 Jan 2022, 10:56

          @SPlatten
          Did I not answer just this in your other post??

          S Offline
          S Offline
          SPlatten
          wrote on 18 Jan 2022, 10:56 last edited by
          #3

          @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

          Kind Regards,
          Sy

          J 1 Reply Last reply 18 Jan 2022, 10:58
          0
          • S SPlatten
            18 Jan 2022, 10:56

            @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

            J Online
            J Online
            JonB
            wrote on 18 Jan 2022, 10:58 last edited by JonB
            #4

            @SPlatten
            I wrote:

            @SPlatten

            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"?

            S 1 Reply Last reply 18 Jan 2022, 11:00
            0
            • J JonB
              18 Jan 2022, 10:58

              @SPlatten
              I wrote:

              @SPlatten

              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"?

              S Offline
              S Offline
              SPlatten
              wrote on 18 Jan 2022, 11:00 last edited by
              #5

              @JonB , that's not the same. Now it's now just the item but its position in the list.

              Kind Regards,
              Sy

              J 1 Reply Last reply 18 Jan 2022, 11:03
              0
              • S SPlatten
                18 Jan 2022, 11:00

                @JonB , that's not the same. Now it's now just the item but its position in the list.

                J Online
                J Online
                JonB
                wrote on 18 Jan 2022, 11:03 last edited by JonB
                #6

                @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.

                S 1 Reply Last reply 18 Jan 2022, 11:06
                3
                • J JonB
                  18 Jan 2022, 11:03

                  @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.

                  S Offline
                  S Offline
                  SPlatten
                  wrote on 18 Jan 2022, 11:06 last edited by
                  #7

                  @JonB , thank you.

                  Kind Regards,
                  Sy

                  1 Reply Last reply
                  0

                  1/7

                  18 Jan 2022, 10:54

                  • Login

                  • Login or register to search.
                  1 out of 7
                  • First post
                    1/7
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved