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. Get the actual row number of tableview after drag and drop
Forum Updated to NodeBB v4.3 + New Features

Get the actual row number of tableview after drag and drop

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 454 Views 1 Watching
  • 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.
  • S Offline
    S Offline
    stereomatching
    wrote on last edited by
    #1

    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?

    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