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. [Solved] Get signal for internalMove in QListView.

[Solved] Get signal for internalMove in QListView.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.1k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        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
        0

        • Login

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