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. Updating ListView selection when a model resets
QtWS25 Last Chance

Updating ListView selection when a model resets

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 2 Posters 1.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.
  • J Offline
    J Offline
    Jpraccio
    wrote on last edited by
    #1

    I am completely reseting a model derived from QAbstractListModel. I need to set the current selection when the model updates. Currently, the currentItem returns null. I can't seem to find a documented way to capture a signal from the model and do some custom stuff on the view.

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

      Hi,

      Do you mean connect to the modelAboutToBeReset to do some stuff ?

      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
      • J Offline
        J Offline
        Jpraccio
        wrote on last edited by
        #3

        Specifically, modelReset would be preferable.

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

          Well depending on what you have in mind, you should connect to both. Typically, if you want to store something like the content of the currently selected item to try and reselect it after the model was updated, you would need to do it following modelAboutToBeReset because modelReset is called once everything is done on the "reset" part.

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

          J 1 Reply Last reply
          0
          • SGaistS SGaist

            Well depending on what you have in mind, you should connect to both. Typically, if you want to store something like the content of the currently selected item to try and reselect it after the model was updated, you would need to do it following modelAboutToBeReset because modelReset is called once everything is done on the "reset" part.

            J Offline
            J Offline
            Jpraccio
            wrote on last edited by Jpraccio
            #5

            @SGaist

            So I have a listview, call that A, that connects to the custom model. I use onComplete when it first loads to to position the view at index 0, onChangeIndex to update my a c++ class with the selection.

            Not sure if this is the best method. But I am dealing with a spinner like gui element and this seemed the best way to get the element that falls in the spinner's "selected" area. (Not really a selection, but when it falls inside the gui spinner's "focus" box).

            When I change a different listview (view B), I completely refresh the data in ListView A. I need to set the index again. Or do something to update my c++ class. It seems after refresh, currentItem becomes null, because it no longer exists. So I am trying to find a way to connect to the modelReset in order to make sure currentItem has the top most index in it. I tried using Connections to connect to the ListView's model property. But that simply told be onResetModel was not there (forget the actual error).

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

              Are you using QML for your GUI ?

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

              J 1 Reply Last reply
              0
              • SGaistS SGaist

                Are you using QML for your GUI ?

                J Offline
                J Offline
                Jpraccio
                wrote on last edited by
                #7

                @SGaist Yes, sorry. QML.

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

                  Do you mean something like a tumbler ?

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

                  J 2 Replies Last reply
                  1
                  • SGaistS SGaist

                    Do you mean something like a tumbler ?

                    J Offline
                    J Offline
                    Jpraccio
                    wrote on last edited by
                    #9

                    @SGaist Well, that's useful... thanks, didn't know it existed. I'll give it a shot.

                    1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Do you mean something like a tumbler ?

                      J Offline
                      J Offline
                      Jpraccio
                      wrote on last edited by
                      #10

                      @SGaist While the Tumbler looks great for a straight forward Tumbler, I am having incredible difficulty customizing it for the custom control I've built. This leads me back to my original question.

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

                        In that case, wouldn't it be simple to take the original humbler code and modify it to look like you want ?

                        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