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. [SOLVED]Making QListWidget Item as Editable from QListWidget Context menu..
Forum Update on Monday, May 27th 2025

[SOLVED]Making QListWidget Item as Editable from QListWidget Context menu..

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 12.6k 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.
  • M Offline
    M Offline
    M_31
    wrote on last edited by
    #1

    I have used QListWidget on my main Dialog window ( TestDlg.cpp).

    I used the following code to make my Items in QListWidget as Editable from the Double click.

    @
    // TestDlg.cpp
    void TestDlg::newItem()
    {
    QListWidgetItem *item = new QListWidgetItem( "<New User>");
    item->setFlags( item->flags() | Qt::ItemIsEditable );

    ui->ListWidget->addItem( item );
    

    }
    @
    But i want to edit the selected Item in QListWidget from QListWidget's Context menu...

    @
    void TestDlg::customContextMenuRequested(const QPoint & pos)
    {
    QPoint globalPos = this->mapToGlobal( pos );

    QMenu menu(this);
    menu.addAction(addNewAction);
    menu.addAction(editAction);

    }
    void TestDlg::createAction()
    {
    addNewAction = new QAction( tr("Add New Item"), this );
    connect( addNewGroupAction, SIGNAL(triggered()), this, SLOT(newItem()) );

    editAction = new QAction( tr("Edit"), this );
    connect( editGroupAction, SIGNAL(triggered()), this, SLOT(editItem()) );
    

    }
    void TestDlg::editItem()
    {
    QListWidgetItem *item = ui->groupsListWidget->currentItem();
    item->setFlags(item->flags() | Qt::ItemIsEditable);
    }
    @

    But i am not able to do the editItem ("ReName") options...
    Please throu some light on this...

    1 Reply Last reply
    0
    • M Offline
      M Offline
      M_31
      wrote on last edited by
      #2

      Now its working..
      after making this change..

      @
      void TestDlg::editItem()
      {
      QListWidgetItem *item = ui->groupsListWidget->currentItem();
      item->setFlags(item->flags() | Qt::ItemIsEditable);

      ui->groupsListWidget->editItem(item);
      

      }
      @

      1 Reply Last reply
      0
      • JonBJ JonB referenced this topic on

      • Login

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