简体   繁体   中英

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

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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