rightclick event in Qt to open a context menu

customContextMenuRequested is emitted when the widget’s contextMenuPolicy is Qt::CustomContextMenu, and the user has requested a context menu on the widget. So in the constructor of your widget you can call setContextMenuPolicy and connect customContextMenuRequested to a slot to make a custom context menu.

In the constructor of plotspace :

this->setContextMenuPolicy(Qt::CustomContextMenu);

connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), 
        this, SLOT(ShowContextMenu(const QPoint &)));

ShowContextMenu slot should be a class member of plotspace like :

void plotspace::ShowContextMenu(const QPoint &pos) 
{
   QMenu contextMenu(tr("Context menu"), this);

   QAction action1("Remove Data Point", this);
   connect(&action1, SIGNAL(triggered()), this, SLOT(removeDataPoint()));
   contextMenu.addAction(&action1);

   contextMenu.exec(mapToGlobal(pos));
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)