Coordinate transformations might be tricky...Here is a code snippet i used long time ago...and the thing is that i'm not sure if i figured it out completely back then...cuz i had the same problem.
//..
// ...
void Widget
::customContextMenuRequested(const QPoint &point
) {
if( index.isValid() )
{
QPoint viewPortPosition
= view
->pos
();
int headerOffset = view->horizontalHeader()->sectionSize(0);
int adjustedHeight = viewPortPos.y() + headerOffset;
viewPortPos.setY(adjustedHeight);
// ...
menu.
exec( mapToGlobal
(QPoint( viewPortPos
+ point
) ) );
}
}
//..
view = new QTableView;
// ...
void Widget::customContextMenuRequested(const QPoint &point)
{
QModelIndex index = view->indexAt(point);
if( index.isValid() )
{
QPoint viewPortPosition = view->pos();
int headerOffset = view->horizontalHeader()->sectionSize(0);
int adjustedHeight = viewPortPos.y() + headerOffset;
viewPortPos.setY(adjustedHeight);
QMenu menu;
// ...
menu.exec( mapToGlobal(QPoint( viewPortPos + point ) ) );
}
}
To copy to clipboard, switch view to plain text mode
Even thought i've used QTableView , i'm sure it's gonna give you an idea...If you find that there is something wrong with my implementation (i'm sure there is
) , i'd be glad to hear the right way to do it!^^
Bookmarks