Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [Solved] Get signal for internalMove in QListView.

    General and Desktop
    2
    3
    1905
    Loading More Posts
    • 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.
    • ?
      A Former User last edited by

      Hello,

      I have been researching how to do this for the whole night now (4 hours approx.) and I am slowly going insane. I have a non-modified simple QListView, user can drag & drop to move items (it doesn't accept external drops etc.)

      How can I register to a signal/event without reimplementing the QListView class? I simply want to update the backend with the new order when an item is reordered.

      Thank you for helping me keep the last little bit of sanity I have.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        I'd rather look on the model side with "rowsMoved":http://doc.qt.io/qt-5/qabstractitemmodel.html#rowsMoved and friends

        Hope it helps

        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 Reply Quote 0
        • ?
          A Former User last edited by

          Hi!I just figured that out, and came to answer my own question, and there is your post :). Thank you so much for the exactly 100% correct answer.

          For future reference:

          There may be more than 1 way to do this. It will work with an event filter. The problem is that from what I read, event filters are not as optimal as signals. They are called often etc. Quick example:

          @// Setting it up
          ui->myObject->installEventFilter(this);

          // Implementation
          bool Bla::eventFilter(QObject *object, QEvent *event) {
          if (object == ui->myObject) {
          if (event->type() == QEvent::ChildRemoved) {
          qDebug() << "drop event!";
          return true;
          } else {
          qDebug() << "Not a drop event";
          return false;
          }
          }
          }@

          The better solution is the rowsMoved signal, more specifically:

          @// Connect the signal like this
          connect(ui->myObject->model(), SIGNAL(rowsMoved(QModelIndex, int, int, QModelIndex, int)), this, SLOT(test(QModelIndex, int, int, QModelIndex, int)));

          // Implementation is the same as usual.@

          BIG sigh of relief.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post