@@ -136,7 +136,7 @@ KsTraceGraph::KsTraceGraph(QWidget *parent)
this, &KsTraceGraph::_updateTimeLegends);
_glWindow.setContextMenuPolicy(Qt::CustomContextMenu);
- connect(&_glWindow, &QTableView::customContextMenuRequested,
+ connect(&_glWindow, &QWidget::customContextMenuRequested,
this, &KsTraceGraph::_onCustomContextMenu);
_scrollArea.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@@ -782,12 +782,15 @@ void KsTraceGraph::_onCustomContextMenu(const QPoint &point)
connect(menu, &KsQuickMarkerMenu::deselect,
this, &KsTraceGraph::deselect);
- QPoint global = mapToGlobal(point);
/*
- * The global coordinates have to be corrected for the offset
- * of the vertical scrollbar.
+ * Note that this slot was connected to the
+ * customContextMenuRequested signal of the OpenGL widget.
+ * Because of this the coordinates of the point are given with
+ * respect to the frame of this widget.
*/
- global.ry() -= _scrollArea.verticalScrollBar()->value();
+ QPoint global = _glWindow.mapToGlobal(point);
+ global.ry() -= menu->sizeHint().height() / 2;
+
menu->exec(global);
}
}
@@ -150,7 +150,7 @@ KsTraceViewer::KsTraceViewer(QWidget *parent)
this, &KsTraceViewer::_searchReset);
_view.setContextMenuPolicy(Qt::CustomContextMenu);
- connect(&_view, &QTableView::customContextMenuRequested,
+ connect(&_view, &QWidget::customContextMenuRequested,
this, &KsTraceViewer::_onCustomContextMenu);
connect(&_view, &QTableView::clicked,
@@ -263,13 +263,22 @@ void KsTraceViewer::_onCustomContextMenu(const QPoint &point)
size_t row = _proxyModel.mapRowFromSource(i.row());
KsQuickContextMenu menu(_data, row, _mState, this);
+ /*
+ * Note that this slot was connected to the
+ * customContextMenuRequested signal of the Table widget.
+ * Because of this the coordinates of the point are given with
+ * respect to the frame of this widget.
+ */
+ QPoint global = _view.mapToGlobal(point);
+ global.ry() -= menu.sizeHint().height() / 2;
+
connect(&menu, &KsQuickContextMenu::addTaskPlot,
this, &KsTraceViewer::addTaskPlot);
connect(&menu, &KsQuickMarkerMenu::deselect,
this, &KsTraceViewer::deselect);
- menu.exec(mapToGlobal(point));
+ menu.exec(global);
}
}
So far I wrongly assumed that the coordinates of the point provided by the customContextMenuRequested signal are given in the reference frame of the parent widget (KsTraceGraph or KsTraceViewer). In fact the signal is emitted by the child widget (KsGLWidget or KsTableView) and the coordinates are given in the reference frame of the child. This patch provides a proper positioning of the menu. Reported-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com> --- kernel-shark-qt/src/KsTraceGraph.cpp | 13 ++++++++----- kernel-shark-qt/src/KsTraceViewer.cpp | 13 +++++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-)