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



  • 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...



  • 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);
    

    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.