How to finish edit mode, get value of QListWidgetItem before and after?
-
- QListWidgetItem: how to finish edit mode ( something like returnPressed ) ?
- QListWidgetItemChanged: need old value and new value when writing a file manager.
connect(new QShortcut(QKeySequence(Qt::Key_F2),this), SIGNAL(activated()),this, SLOT(rename())); void MainWindow::rename() { QList<QListWidgetItem*> list = ui->listWidget->selectedItems(); foreach(QListWidgetItem *LWI, list) { ui->listWidget->openPersistentEditor(LWI); } } void MainWindow::listWidgetItemChanged(QListWidgetItem *LWI) { QString oldName = ui->listWidget->currentItem()->text(); QString oldPath = path + "/" + oldName; QString newPath = path + "/" + LWI->text(); qDebug() << "rename" << oldPath << newPath; if (QFile::rename(oldPath, newPath)) { genList(path); }else{ LWI->setText(oldName); QMessageBox::critical(NULL, "Error", oldName + " can not rename to " + LWI->text() + " !", QMessageBox::Ok); } } -
Do you want to get the value of same ListWidget item once the user click it, changes it & finishes it. IF this is the case, can you check the following signals.
- itemActivate(..) - Now save the current value
- itemChanged(..) - Now take the new value.