Important: Please read the Qt Code of Conduct -

[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


    I'd rather look on the model side with "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

    // 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