A popup menu in Qt is called a context menu.
Implement the context menu events and signals.
A popup menu in Qt is called a context menu.
Implement the context menu events and signals.
QTableWidgetItem * itemAt ( const QPoint & point ) const
Qt Code:
{ connect(pAddAction,SIGNAL(triggered()),this,(slotAdd())); connect(pRemoveAction ,SIGNAL(triggered()),this,(slotRemove())); connect(pUpdateAction ,SIGNAL(triggered()),this,(slotUpdate())); // pContextMenu->addAction(pAddAction); pContextMenu->addAction(pRemoveAction ); pContextMenu->addAction(pUpdateAction ); // pContextMenu->exec( e->globalPos() ); delete pContextMenu; pContextMenu = NULL; }To copy to clipboard, switch view to plain text mode
katta_ashish (9th September 2010)
Thank you very much for your valuable reply.....My problem is solved now with some of your help and some of mine coding.I am pasting the code also so that it can help others also...
First create a signal and slot in main program like this
connect(ui->tableWidget,SIGNAL(customContextMenuRequested(con st QPoint &)),this,SLOT(ProvideContextMenu(const QPoint &)));
and then just create the slots functions for them like this....
void MainWindow::ProvideContextMenu(const QPoint &pos)
{
item = ui->tableWidget->itemAt(pos);
// QPoint globalPos = ui->tableWidget->mapToGlobal(pos);
QAction *pAddAction = new QAction("Add",ui->tableWidget);
connect(pAddAction,SIGNAL(triggered()),this,SLOT(n ewRow()));
QAction *pRemoveAction = new QAction("Remove",ui->tableWidget);
connect(pRemoveAction ,SIGNAL(triggered()),this,SLOT(deleteRow()));
QAction *pUpdateAction = new QAction("Update",ui->tableWidget);
//connect(pUpdateAction ,SIGNAL(triggered()),this,SLOT(Update()));
QMenu *pContextMenu = new QMenu( this);
pContextMenu->addAction(pAddAction);
pContextMenu->addAction(pRemoveAction );
pContextMenu->addAction(pUpdateAction );
pContextMenu->exec( mapToGlobal(pos) );
delete pContextMenu;
pContextMenu = NULL;
}
void MainWindow::newRow()
{
int row = ui->tableWidget->rowCount();
ui->tableWidget->insertRow(row);
}
void MainWindow::deleteRow()
{
int row = ui->tableWidget->row(item);
ui->tableWidget->removeRow(row);
}
Do not forget to declare them in .h file or wherever you want....
Last edited by katta_ashish; 9th September 2010 at 07:23.
Bookmarks