Originally Posted by
tbscope
Then you don't mind explaining it?
Ok i do not mind...
if( ui->listWidget->selectionModel()->hasSelection() ){
if( ui->listWidget->selectionModel()->hasSelection() ){
To copy to clipboard, switch view to plain text mode
If you had selected something on the listWidget then do the following...
if( ui->listWidget->currentIndex().row() != 0 ){
int row = ui->listWidget->currentIndex().row();
if( ui->listWidget->currentIndex().row() != 0 ){
int row = ui->listWidget->currentIndex().row();
To copy to clipboard, switch view to plain text mode
That means that if you have selected something then int row and row will be the currentIndex.row... ( When you select for example the second item of an listWidget the row will be 2... )
QModelIndex currentIndex
= ui
->listWidget
->currentIndex
();
QModelIndex currentIndex = ui->listWidget->currentIndex();
To copy to clipboard, switch view to plain text mode
currentIndex will be the item that you selected
QModelIndex indexAbove = ui->listWidget->model()->index( row-1, 0, QModelIndex() );
To copy to clipboard, switch view to plain text mode
indexAbove will be the item above the one you selected as it is row-1 ( we declared before that the row is the row of the selected item )
QString selectedString
= ui
->listWidget
->currentIndex
().
data().
toString();
QString selectedString = ui->listWidget->currentIndex().data().toString();
To copy to clipboard, switch view to plain text mode
Here we convert the currentindex to string
ui->listWidget->model()->setData( currentIndex, indexAbove.data().toString() );
ui->listWidget->model()->setData( currentIndex, indexAbove.data().toString() );
To copy to clipboard, switch view to plain text mode
Here we say to replace the current index with the indexAbove
ui->listWidget->model()->setData( indexAbove, selectedString );
ui->listWidget->model()->setData( indexAbove, selectedString );
To copy to clipboard, switch view to plain text mode
And here to replace the indexAbove with the current index
ui->listWidget->setCurrentIndex( indexAbove );
ui->listWidget->setCurrentIndex( indexAbove );
To copy to clipboard, switch view to plain text mode
Finnally with this function we say the one that we have selected at the start once it has gone an indexabove to be selected again..
Bookmarks