So, I've been working with PyQt5 and their implementation of chromium to make my own web browser in python. But, I've come across an issue, after adding a tabs system and a settings menu, some of the functions of the right click menu don't work. For instance, I can't open a link in a new tab or window, I can't view a page source, I can't save a page, I can't save a link, and I can't save a file. Although, the actual browser functions like going to a different page from the right click menu does work. I want to try and make it so at least I can open a link in a new tab or window and I can view the page source So, that is the issue.
At the start of defining my web browsers class I have a line.
self.setContextMenuPolicy(QtCore.Qt.NoContextMenu)
But, it doesn't seem to do anything for the program at all, even when removed.
This is the class.
#Main window.
class MainWindow(QMainWindow):
#Constructor.
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.browser = QWebEngineView()
self.browser.setUrl(QUrl(HOMEPAGE))
self.setCentralWidget(self.browser)
self.setWindowIcon(QtGui.QIcon("Logo.png"))
self.setContextMenuPolicy(QtCore.Qt.NoContextMenu)
self.showMaximized()
The way I add tabs is through this function.
#Method for adding new tab.
def add_new_tab(self, qurl = None, label ="Blank"):
#If url is blank.
if qurl is None:
#Creating a url to be the default one.
qurl = QUrl(self.homepage)
#Creating a QWebEngineView object.
browser = QWebEngineView()
#Setting url to browser.
browser.setUrl(QUrl(self.homepage))
#Setting tab index.
i = self.tabs.addTab(browser, label)
self.tabs.setCurrentIndex(i)
#Update the url
browser.urlChanged.connect(lambda qurl, browser = browser:
self.update_urlbar(qurl, browser))
#Set the tab title.
browser.loadFinished.connect(lambda _, i = i, browser = browser:
self.tabs.setTabText(i, browser.page().title()))
#Update the tab's icon.
self.tabs.setTabIcon(i, browser.icon())
browser.iconChanged.connect(lambda icon, browser=browser: self.update_icon(browser, icon))
#Making the page more readable while having a closer up view of it.
#browser.setZoomFactor(1.5)
Also, I use this function to change the page of a tab.
#When tab is changed.
def current_tab_changed(self, i):
#Get the current url.
qurl = self.tabs.currentWidget().url()
#Update that url.
self.update_urlbar(qurl, self.tabs.currentWidget())
#Update that title.
self.update_title(self.tabs.currentWidget())
I have tried many solutions to getting the menus to work, for instance trying to change the menu, or trying to have functions that do those tasks but nothing has worked at all. Any help to fix this issue would be appreciated.