C++ (Qt)struct CData { QString mName, mText;};
void MainWindow::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous){ map[previous->text()].mText = ui->textEdit->toPlainText(); ui->textEdit->setPlainText(map[current->text()].mText);}
void currentItemChangedByUser(QListWidgetItem *current, QListWidgetItem *previous);
void ListWidget::mousePressEvent(QMouseEvent *event){ QListWidget* previous = currentItem(); QListWidget::mousePressEvent(event); QListWidget* current = currentItem(); if (current != previous) emit currentItemChangedByUser(current, previous);}void ListWidget::keyPressEvent(QKeyEvent *event){ QListWidget* previous = currentItem(); QListWidget::keyPressEvent(event); QListWidget* current = currentItem(); if (current != previous) emit currentItemChangedByUser(current, previous);}