PDA

View Full Version : Context menu on Cells of QTableWidget



core_st
19th October 2010, 16:54
I'm sorry that i created another topic about QTableWidget and Context menu, but after reading previous topics i could not realize the problem. So, please help me.

i have QTableWidget on form. It's used for list of files. Table has 2 columns. First - it's number of row, second - name of file. So, i need create context menu, which will open only by click on tableWidget. That's not all. Also i need to check: click was performed on cell or on empty table?

if found an example of context menu:
in header:

void contextMenuEvent( QContextMenuEvent * e );
then somewhere:


QObject::connect (ui->tableWidget,SIGNAL(customContextMenuRequested(cons t QPoint &)),this,SLOT(contextMenuEvent(QContextMenuEvent*)) );

and :


void MainWindow::contextMenuEvent( QContextMenuEvent * e )
{

QAction *pRemoveAction = new QAction("Remove from list",this);
/*in this place i need something like
if(cell_click())pRemoveAction->setEnabled(true); else
pRemoveAction->setEnabled(true);
*/
connect(pRemoveAction ,SIGNAL(triggered()),this,SLOT(toolButton_DeleteTr ack_Clicked()));
//
QMenu *pContextMenu = new QMenu( this);
pContextMenu->addAction(pRemoveAction );
//
pContextMenu->exec( e->globalPos() );

delete pContextMenu;
pContextMenu = NULL;
}

but this menu is open after clicking anywhere on the form((
P.S. Sorry for my bad English