Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ListView: Is there a signal after the list view has been updated?
Forum Updated to NodeBB v4.3 + New Features

ListView: Is there a signal after the list view has been updated?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 748 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.
  • M Offline
    M Offline
    maxwell31
    wrote on last edited by
    #1

    Hi,

    I have a list view which displays a C++ model. After the model is updated (e.g. rows added or removed) I want to use the positionViewAtIndex function the center an item in the listview. To which system should I listen to?

    Can I listen to the signals of the model, e.g. endInsertRows? I am aksing because I don't understand the order in which things happen. After the model changed, the list view could need to create new components, so postionViewAtIndex should happen after this happened, right?

    eyllanescE 1 Reply Last reply
    0
    • M maxwell31

      Hi,

      I have a list view which displays a C++ model. After the model is updated (e.g. rows added or removed) I want to use the positionViewAtIndex function the center an item in the listview. To which system should I listen to?

      Can I listen to the signals of the model, e.g. endInsertRows? I am aksing because I don't understand the order in which things happen. After the model changed, the list view could need to create new components, so postionViewAtIndex should happen after this happened, right?

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

      @maxwell31 There are many signals for each type of modification(See https://doc.qt.io/qt-5/qabstractitemmodel.html#signals). A possible solution is that you create a custom class where you create a signal that is connected to the other signals and then use that signal in QML:

      class FooModel: public XModel{
      // ...
      
      signals:
          void fooSignal();
      //...
      };
      
      ```cpp
      // in constructor
      connect(this, &FooModel::rowsRemoved, this, &FooModel::fooSignal);
      connect(this, &FooModel::rowsInserted, this, &FooModel::fooSignal);
      connect(this, &FooModel::modelReset, this, &FooModel::fooSignal);
      connect(this, &FooModel::dataChanged, this, &FooModel::fooSignal);
      // ...
      

      Then

      Connections: {
          target: cppModel
          onFooSignal: function(){
              console.log("Foo");
          }
      }
      

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxwell31
        wrote on last edited by
        #3

        What I meant was rather the following:

        Lets assume a model is reset. If I connect to endModelReset, and call positionViewAtIndex, can I be sure, that the ListView already completed constructing the delegates, so that positionViewAtIndex does what it should?

        1 Reply Last reply
        0
        • GrecKoG Offline
          GrecKoG Offline
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #4

          No you can't, since the ListView might not even create the delegates if those are of the view.
          However I would assume it to work regardless of this.
          You could wrap your positionViewAtIndex call in a Qt.callLater to be sure it's not called too soon.

          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