简体   繁体   English

如何在Qt Creator中编辑QtWebKit的右键单击上下文菜单?

[英]How to edit QtWebKit's right-click context menu in Qt Creator?

Alright, here's my dillema. 好吧,这是我的dillema。 I am making a simple application with Qt Creator that makes use of Webkit. 我正在使用Qt Creator制作一个使用Webkit的简单应用程序。 I thought Qt Creator would have an easy way to edit the right-click context menu with the signals and slots editor, but this has proven to not be true. 我认为Qt Creator可以通过信号和插槽编辑器轻松编辑右键单击上下文菜单,但事实证明这不是真的。 I know webkit has classes that have to do with the context menu, but I don't know how to access them through Qt Creator. 我知道webkit有与上下文菜单有关的类,但我不知道如何通过Qt Creator访问它们。

I need to edit the "Open Link in New Window" part of the context menu so that it opens my application up in a new window when a link is followed, but as I said previously, I can't think of a way to edit it without compiling a modified QtWebKit from source, which would be a pain. 我需要编辑上下文菜单中的“在新窗口中打开链接”部分,以便在跟踪链接时在新窗口中打开我的应用程序,但正如我之前所说,我想不出一种编辑方式它没有从源代码编译修改过的QtWebKit,这将是一个痛苦。

Any answers would be appreciated, and if it makes any difference, I'm mainly a C#/.NET developer, and I've jsut started working with Qt and C++. 任何答案都会受到赞赏,如果它有所不同,我主要是一个C#/ .NET开发人员,我已经开始使用Qt和C ++。

The QWidget::contextMenuEvent( QContextMenuEvent * event ) is a "virtual protected" function. QWidget :: contextMenuEvent(QContextMenuEvent * event)是一个“虚拟保护”功能。
You can inherit the QWebView, and then override "contextMenuEvent". 您可以继承QWebView,然后覆盖“contextMenuEvent”。

If what you need is just to handle "Open in New Window" action, I suggest to reimplement virtual protected QWebView::createWindow. 如果您只需要处理“在新窗口中打开”操作,我建议重新实现虚拟保护的QWebView :: createWindow。 Reimplementing contextMenuEvent from scratch could be complicated without using createStandardContextMenu, which directs "Open in New Window" to createWindow. 如果不使用createStandardContextMenu从头开始重新实现contextMenuEvent,它会指向“在新窗口中打开”来创建窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM