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