Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to finish edit mode, get value of QListWidgetItem before and after?
Forum Updated to NodeBB v4.3 + New Features

How to finish edit mode, get value of QListWidgetItem before and after?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 432 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by sonichy
    #1
    1. QListWidgetItem: how to finish edit mode ( something like returnPressed ) ?
    2. 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);
        }
    }
    

    https://github.com/sonichy

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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.

      1. itemActivate(..) - Now save the current value
      2. itemChanged(..) - Now take the new value.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved