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, choice and revert

QListWidget, choice and revert

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 457 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

    I am using a QListWidget to allow selection of a data source, when a choice is made I check the content on the form for changes and if any changes have been made but not submitted I prompt the user to make a decision either to stay on the form with no change in selection or to go ahead with the new selection.

    Is there any way to get the original selection index from the QListWidget at the time the prompt is given to the user so that if the decision is not to change the list can be reverted back to the original position?

    Kind Regards,
    Sy

    jsulmJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      I am using a QListWidget to allow selection of a data source, when a choice is made I check the content on the form for changes and if any changes have been made but not submitted I prompt the user to make a decision either to stay on the form with no change in selection or to go ahead with the new selection.

      Is there any way to get the original selection index from the QListWidget at the time the prompt is given to the user so that if the decision is not to change the list can be reverted back to the original position?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @SPlatten You can store the last selection index in a member variable and resore it if needed.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      SPlattenS 1 Reply Last reply
      3
      • jsulmJ jsulm

        @SPlatten You can store the last selection index in a member variable and resore it if needed.

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

        @jsulm , thank you, I'm using the currentItemChanged signal which has current and previous parameters which are of type QListWidgetItem, looking at the help page for this class:
        https://doc.qt.io/qt-5/qlistwidgetitem.html

        How do I determine its position in the list?

        [Edit], Sorry I see now, using the setCurrentItem of the QListWidget and passing the item.

        Kind Regards,
        Sy

        JonBJ 1 Reply Last reply
        0
        • SPlattenS SPlatten

          @jsulm , thank you, I'm using the currentItemChanged signal which has current and previous parameters which are of type QListWidgetItem, looking at the help page for this class:
          https://doc.qt.io/qt-5/qlistwidgetitem.html

          How do I determine its position in the list?

          [Edit], Sorry I see now, using the setCurrentItem of the QListWidget and passing the item.

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

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

          1 Reply Last reply
          1

          • Login

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