How to disable contextMenu from QWebEngineView?

Viewed 1250

I want to disable the right click menu which appears by default when you create a QWebEngineView.

import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtCore import QUrl

app = QApplication(sys.argv)

webBrowser = QWebEngineView()

#Some line here to delete the contextMenu

webBrowser.load(QUrl("https://stackoverflow.com/"))
webBrowser.show()

sys.exit(app.exec_())

In the doc we can find a class QWebEngineContextMenuData which "provides context data for populating or extending a context menu with actions..." but nothing to delete in here?

1 Answers

To disable the default widgets menu then the contextMenuPolicy must be set to Qt::NoContextMenu:

webBrowser.setContextMenuPolicy(Qt.NoContextMenu)
Related