我在 Qt 5.10.1 中遇到了 QWebEngineView 的问题。当我右键单击页面中的“输入”字段时,上下文菜单中未显示“粘贴”操作。
这是我在 contextMenuEvent 上的代码:
void WebView::contextMenuEvent(QContextMenuEvent *event)
{
QMenu *menu = page()->createStandardContextMenu();
const QList<QAction*> actions = menu->actions();
auto it = std::find(actions.cbegin(), actions.cend(), page()->action(QWebEnginePage::ViewSource));
if (it != actions.cend()) {
(*it)->setVisible(false);
}
menu->popup(event->globalPos());
}
createStandardContextMenu() 它在某些情况下可以正常工作,例如,如果我选择文本,上下文菜单会正确显示“复制”或“取消选择”操作。
有人知道吗?