[Solved] Get signal for internalMove in QListView.



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


  • Lifetime Qt Champion

    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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.