if (smodel==0) {
return;
}
QModelIndexList selectionList =smodel->selectedIndexes();
QItemSelection selection
( ui.
tableWidget->selectionModel
()->selection
() );
QList<int> rows;
foreach
( const QModelIndex & index, selection.
indexes() ) { rows.append( index.row() );
}
qSort( rows );
int prev = -1;
for( int i = selectionList.length() - 1; i >= 0; i -= 1 ) {
int current = rows[i];
if( current != prev ) {
ui.tableWidget->setItem(current,0,itemBelow);
ui.tableWidget->setItem(current+1,0,item);
prev = current;
}
}
QItemSelectionModel *smodel= ui.tableWidget->selectionModel();
if (smodel==0) {
return;
}
QModelIndexList selectionList =smodel->selectedIndexes();
QItemSelection selection( ui.tableWidget->selectionModel()->selection() );
QList<int> rows;
foreach( const QModelIndex & index, selection.indexes() ) {
rows.append( index.row() );
}
qSort( rows );
int prev = -1;
for( int i = selectionList.length() - 1; i >= 0; i -= 1 ) {
int current = rows[i];
if( current != prev ) {
QTableWidgetItem *item = ui.tableWidget->takeItem(current,0);
QTableWidgetItem *itemBelow = ui.tableWidget->takeItem(current+1,0);
ui.tableWidget->setItem(current,0,itemBelow);
ui.tableWidget->setItem(current+1,0,item);
prev = current;
}
}
To copy to clipboard, switch view to plain text mode
Now, it works. moves selected!
seems still have little problem; my selected blues not move wth current moving.
Bookmarks