PDA

View Full Version : How to pass the item value from rightClick popud menu to TextEdit



altobeta
13th March 2009, 03:19
How to get the value from item treeWidget after i right click on the item and choose "Registration" option from popud menu
then item value will show up in TextEdit.

Please Someone see and modify my code


/MyProgram.cpp
///////////////////////////////////////////////////////////////

menu = new QMenu( this );
Register = new QAction(tr("Registration"), this);
connect(Register, SIGNAL(triggered()), qApp, SLOT(RegisterMenu()));
menu->addAction( Register);

ui.treeWidget->setContextMenuPolicy( Qt::CustomContextMenu );
connect( ui.treeWidget, SIGNAL( customContextMenuRequested( const QPoint & )),
this, SLOT( customContentsMenu( const QPoint & )));


void MyProgram::customContentsMenu( const QPoint &pos )
{

QTreeWidgetItem *item = ui.treeWidget->itemAt(pos);
if (!item)
return;

menu->exec(ui.treeWidget->viewport()->mapToGlobal(pos));
}


void MyProgram::RegisterMenu()
{
//the textedit should show up the item value here which i select from right click item on TreeWidget, but i don't know how to get the value

}

munna
18th March 2009, 04:56
You can select the item on to which the user has right-clicked and then change the text. Here's the code



void MyProgram::customContentsMenu( const QPoint &pos )
{
QTreeWidgetItem *item = ui.treeWidget->itemAt(pos);
if (!item)
return;
ui.treeWidget->setCurrentItem(item);

menu->exec(ui.treeWidget->viewport()->mapToGlobal(pos));
}

void MyProgram::RegisterMenu()
{
QTreeWidgetItem *item = ui.treeWidget->currentItem();
if(item)
item->setText("Text that you want");
}