Get the actual row number of tableview after drag and drop



  • At first, the data of the tableview are

    1 : apple
    2 : pie
    3 : banana

    After drag and drop((only drag and drop on itself)) the item on the tableview, the data of the tableview are

    3 : banana
    2 : pie
    1 : apple

    but when I want to iterate the item of the model one by one

    codes
    @for(int i = 0; i != rowCount(); ++i){
    if(item(row, Fruit)){
    return item(row, Fruit)->data(Qt::DisplayRole).value<QString>();
    }
    }@

    it print the data as

    1 : apple
    2 : pie
    3 : banana

    expected result

    3 : banana
    2 : pie
    1 : apple

    How could I get the "actual" number after drag and drop?

    The easiest solution I can think of is create one more column to store the row number of the model, then override the dropEvent, update the row number when the user drop their row.Any easier way to do it?


Log in to reply
 

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