Don't use QCursor::pos() to position context menus

This won't work under Wayland.
This commit is contained in:
Martchus 2019-07-20 18:23:43 +02:00
parent 318542c658
commit 31de4955e6
2 changed files with 6 additions and 6 deletions

View File

@ -1155,7 +1155,7 @@ void MainWindow::changePassword()
/*! /*!
* \brief Shows the tree view context menu. * \brief Shows the tree view context menu.
*/ */
void MainWindow::showTreeViewContextMenu() void MainWindow::showTreeViewContextMenu(const QPoint &pos)
{ {
if (!m_file.hasRootEntry()) { if (!m_file.hasRootEntry()) {
return; return;
@ -1183,13 +1183,13 @@ void MainWindow::showTreeViewContextMenu()
std::bind(&EntryModel::setData, m_entryModel, std::cref(selected), QVariant(!nodeEntry->isExpandedByDefault()), DefaultExpandedRole)); std::bind(&EntryModel::setData, m_entryModel, std::cref(selected), QVariant(!nodeEntry->isExpandedByDefault()), DefaultExpandedRole));
contextMenu.addAction(action); contextMenu.addAction(action);
} }
contextMenu.exec(QCursor::pos()); contextMenu.exec(m_ui->treeView->mapToGlobal(pos));
} }
/*! /*!
* \brief Shows the table view context menu. * \brief Shows the table view context menu.
*/ */
void MainWindow::showTableViewContextMenu() void MainWindow::showTableViewContextMenu(const QPoint &pos)
{ {
// check whether there is a selection at all // check whether there is a selection at all
const QModelIndexList selectedIndexes = m_ui->tableView->selectionModel()->selectedIndexes(); const QModelIndexList selectedIndexes = m_ui->tableView->selectionModel()->selectedIndexes();
@ -1265,7 +1265,7 @@ void MainWindow::showTableViewContextMenu()
contextMenu.addAction(openUrlAction); contextMenu.addAction(openUrlAction);
} }
contextMenu.exec(QCursor::pos()); contextMenu.exec(m_ui->tableView->mapToGlobal(pos));
} }
void MainWindow::showFileDetails() void MainWindow::showFileDetails()

View File

@ -97,8 +97,8 @@ private slots:
void copyFields(); void copyFields();
void insertFieldsFromClipboard(); void insertFieldsFromClipboard();
// showing context menus // showing context menus
void showTreeViewContextMenu(); void showTreeViewContextMenu(const QPoint &pos);
void showTableViewContextMenu(); void showTableViewContextMenu(const QPoint &pos);
// other // other
void showFileDetails(); void showFileDetails();
void showContainingDirectory(); void showContainingDirectory();