Reputation: 91
I am trying to move the listwidget item programmatically. I am able to move the listwidget successfully if the move is in current view. If i try to move the list widget item across view ( i.e Using scrollbar ), move is not working as expected. i.e List widget item is not reflecting
code snip:
void func(int fromPage, int toPage)
{
QListWidget* expListWidget =i.next();
QListWidgetItem* widgetItem = expListWidget->takeItem(fromPage);
expListWidget->insertItem(toPage,widgetItem);
}
Upvotes: 0
Views: 2074
Reputation: 4344
Here is an example how to move items up and down independently of where they are located:
QListWidget* lw1 = new QListWidget;
for (int i = 0; i < 500 ; i++)
{
QListWidgetItem* item = new QListWidgetItem(QString::number(i));
lw1->addItem(item);
}
//move from lower part to the top
QListWidgetItem* i = lw1->takeItem(400);
lw1->insertItem(0, i);
//move from the top to the lower part of the list
i = lw1->takeItem(1);
lw1->insertItem(400, i);
Upvotes: 1