Hi,

I am trying to swap the content of a QListWidget. Perhaps I am not using the right methods ... or maybe I need to use the listview + model instead ?

The context here is that I have a plotter and I am loading multple files. Each files has its own tab with the plotted data. Each tab contains an object with the filename, channelList, etc ..

The "Channel list" is in a general QListWidget and I would like to switch the content of that widget when I switch tab.

Each dataLog object contains the list of channels with a QList that contains items property:
Qt Code:
  1. QList<QListWidgetItem*> itemList;
To copy to clipboard, switch view to plain text mode 

And here's the handler when I change tabs :

Qt Code:
  1. void MainWindow::on_tabWidget_logs_currentChanged(int index)
  2. {
  3. foreach(logData* l, this->openedLogs)
  4. {
  5. if(l->parentWidget == ui->tabWidget_logs->widget(index))
  6. {
  7.  
  8. int count = ui->listWidget_channels->count();
  9.  
  10. //currentLog->itemList.clear(); // This actually deletes the items in the dataLog object so it's not good
  11.  
  12. // This doesnt seem to be working since all the items are still in the QListWidget
  13. for ( int i=0; i<count; i++)
  14. {
  15. ui->listWidget_channels->takeItem(i);
  16. }
  17.  
  18. currentLog = l;
  19. // Take the items from the log object and populate the QListWidget with them
  20. foreach(QListWidgetItem *i, currentLog->itemList)
  21. {
  22. ui->listWidget_channels->addItem(i);
  23. }
  24. ui->listWidget_channels->sortItems();
  25. break;
  26. }
  27. }
  28. }
To copy to clipboard, switch view to plain text mode