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?
Forum Updated to NodeBB v4.3 + New Features

QListWidget, get item position in list?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 6.1k Views 1 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on 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

    JonBJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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.

      SPlattenS 1 Reply Last reply
      3
      • SPlattenS SPlatten

        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.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

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

        SPlattenS 1 Reply Last reply
        0
        • JonBJ JonB

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

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on 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

          JonBJ 1 Reply Last reply
          0
          • SPlattenS SPlatten

            @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

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on 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"?

            SPlattenS 1 Reply Last reply
            0
            • JonBJ JonB

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

              SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on 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

              JonBJ 1 Reply Last reply
              0
              • SPlattenS SPlatten

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

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on 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.

                SPlattenS 1 Reply Last reply
                3
                • JonBJ 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.

                  SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by
                  #7

                  @JonB , thank you.

                  Kind Regards,
                  Sy

                  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