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:
QList<QListWidgetItem*> itemList;
QList<QListWidgetItem*> itemList;
To copy to clipboard, switch view to plain text mode
And here's the handler when I change tabs :
void MainWindow::on_tabWidget_logs_currentChanged(int index)
{
foreach(logData* l, this->openedLogs)
{
if(l->parentWidget == ui->tabWidget_logs->widget(index))
{
int count = ui->listWidget_channels->count();
//currentLog->itemList.clear(); // This actually deletes the items in the dataLog object so it's not good
// This doesnt seem to be working since all the items are still in the QListWidget
for ( int i=0; i<count; i++)
{
ui->listWidget_channels->takeItem(i);
}
currentLog = l;
// Take the items from the log object and populate the QListWidget with them
{
ui->listWidget_channels->addItem(i);
}
ui->listWidget_channels->sortItems();
break;
}
}
}
void MainWindow::on_tabWidget_logs_currentChanged(int index)
{
foreach(logData* l, this->openedLogs)
{
if(l->parentWidget == ui->tabWidget_logs->widget(index))
{
int count = ui->listWidget_channels->count();
//currentLog->itemList.clear(); // This actually deletes the items in the dataLog object so it's not good
// This doesnt seem to be working since all the items are still in the QListWidget
for ( int i=0; i<count; i++)
{
ui->listWidget_channels->takeItem(i);
}
currentLog = l;
// Take the items from the log object and populate the QListWidget with them
foreach(QListWidgetItem *i, currentLog->itemList)
{
ui->listWidget_channels->addItem(i);
}
ui->listWidget_channels->sortItems();
break;
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks