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. Rename an item in Qlistview and Qlistwidget

Rename an item in Qlistview and Qlistwidget

Scheduled Pinned Locked Moved General and Desktop
listview
6 Posts 2 Posters 3.9k Views 2 Watching
  • 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.
  • RatzzR Offline
    RatzzR Offline
    Ratzz
    wrote on last edited by Ratzz
    #1

    I have an listview where several items present (item1..item9) . I want to remane items using doubleclick . If the renamed item name is similar to the already present item name then an warning message should be dispalyed. I tried this way

     connect(ui->listView_messages,SIGNAL(objectNameChanged(QString)),this,SLOT(renameListView(QString)));
    
    void Window::on_listView_Messages_doubleClicked()
    {
    disconnect(ui->listView_Messages,SIGNAL(objectNameChanged(QString)),this,SLOT(renameListView(QString)));
    ui->listView_Messages->setEditTriggers(QAbstractItemView::DoubleClicked);
    connect(ui->listView_Messages,SIGNAL(objectNameChanged(QString)),this,SLOT(renameListView(QString)));
    }
    
    void Window::renameListView(QString str)
    {
        for(int i=0;i<messageList.count();i++)
      {
       if(messageList.at(i).messageName== str)
       {
         QMessageBox *msgBox = new QMessageBox(QMessageBox::Warning,"Warning","Message Name already exists");
                msgBox->exec();
    
            }
        }
    }
    

    What is the proper way to do it ?

    --Alles ist gut.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You need to make your items editable before you can modify them

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      RatzzR 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        You need to make your items editable before you can modify them

        RatzzR Offline
        RatzzR Offline
        Ratzz
        wrote on last edited by Ratzz
        #3

        @SGaist
        using setEditTriggers cant we make it editable ?
        Ok now i have made it editable.
        can i rename using this

        connect(ui->listView_messages,SIGNAL(objectNameChanged(QString)),this,SLOT(renameListView(QString)));
        void Window::renameListView(QString str)
        {
            for(int i=0;i<messageList.count();i++)
          {
           if(messageList.at(i).messageName== str)
           {
             QMessageBox *msgBox = new QMessageBox(QMessageBox::Warning,"Warning","Message Name already exists");
                    msgBox->exec();
        
                }
            }
        }

        --Alles ist gut.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          It still depends on the underlaying model. In your case, it seems to be already OK.

          IIRC, if you need validation you should implement your own QStyledItemDelegate and add the validation to your editor

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          RatzzR 1 Reply Last reply
          0
          • SGaistS SGaist

            It still depends on the underlaying model. In your case, it seems to be already OK.

            IIRC, if you need validation you should implement your own QStyledItemDelegate and add the validation to your editor

            RatzzR Offline
            RatzzR Offline
            Ratzz
            wrote on last edited by Ratzz
            #5

            @SGaist
            I am not able to prevent the renaming to the already entered name .

            --Alles ist gut.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              That's why you should handle that at the editor level not after

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

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