PaulCrp
PaulCrp

Reputation: 978

How to disable contextMenu from QWebEngineView?

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?

Upvotes: 2

Views: 2781

Answers (2)

eyllanesc
eyllanesc

Reputation: 243897

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

webBrowser.setContextMenuPolicy(Qt.ContextMenuPolicy.NoContextMenu)

Upvotes: 6

IkonoDim
IkonoDim

Reputation: 60

In PyQt6 it is:

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

Upvotes: 1

Related Questions