CustomContext menu is not displaying in proper position
-
The context menu in program is not displaying at the position of the pointer...it is displaying somewhere else...
Please suggest me what changes i need to do for my program?The code is:
@
void MainWindow::ProvideContextMenu(const QPoint &pos)
{
QTableWidgetItem *item=filesTable->itemAt(pos);QString cell=item->text(); cout<<"EVENT GENERATED..."<<cell.toStdString()<<endl; //QString item=filesTable->itemAt(pos); QAction *pAddAction= new QAction("add",filesTable); QAction *pSplitAction= new QAction("SPLIT",filesTable); QMenu *pContextMenu = new QMenu( this); pContextMenu->addAction(pAddAction); pContextMenu->addAction(pSplitAction); pContextMenu->exec(mapToGlobal(pos));
}
@ -
Hmm. Have you tried move your ProvideContextMenu(const QPoint &pos) function to the filesTable class implementation. This way you would not have to map the position.
It's just a guess but maybe your problem is related to this exception stated in "the doc of customContextMenuRequested(..)":http://developer.qt.nokia.com/doc/qt-4.8/qwidget.html#customContextMenuRequested:
bq. The position pos is the position of the context menu event that the widget receives. Normally this is in widget coordinates. The exception to this rule is QAbstractScrollArea and its subclasses that map the context menu event to coordinates of the viewport().
Since QAbstractScrollArea is inherited by QAbstractItemView, QGraphicsView, QMdiArea, QPlainTextEdit, QScrollArea, and QTextEdit