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

我怕爱的太早我们不能终老 提交于 2019-12-06 06:42:02

问题


Alright, here's my dillema. I am making a simple application with Qt Creator that makes use of 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. 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.

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.

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++.


回答1:


The QWidget::contextMenuEvent( QContextMenuEvent * event ) is a "virtual protected" function.
You can inherit the QWebView, and then override "contextMenuEvent".




回答2:


If what you need is just to handle "Open in New Window" action, I suggest to reimplement virtual protected QWebView::createWindow. Reimplementing contextMenuEvent from scratch could be complicated without using createStandardContextMenu, which directs "Open in New Window" to createWindow.



来源:https://stackoverflow.com/questions/3327222/how-to-edit-qtwebkits-right-click-context-menu-in-qt-creator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!