How to disable contextMenu from QWebEngineView?

2.2k views Asked by At

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?

2

There are 2 answers

1
eyllanesc On BEST ANSWER

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

webBrowser.setContextMenuPolicy(Qt.ContextMenuPolicy.NoContextMenu)
0
IkonoDim On

In PyQt6 it is:

webbrowser.setContextMenuPolicy(PyQt6.QtCore.Qt.ContextMenuPolicy.NoContextMenu)