Greetings
I am learning py3 and trying to use PyQt5.QtWebEngine .
But having lots of problems , like no ‘target=“_blank”’ support.
Here is latest disaster:
import sys
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication, QMainWindow, QTabWidget, QWidget, QVBoxLayout
from PyQt5.QtWebEngineWidgets import QWebEngineView
class Browser(QMainWindow):
def __init__(self):
super().__init__()
# Create a tab widget to manage multiple tabs
self.tabs = QTabWidget()
self.setCentralWidget(self.tabs)
self.tabs.setDocumentMode(True)
self.tabs.setTabsClosable(True)
self.tabs.tabCloseRequested.connect(self.close_current_tab)
# Open the initial tab with the default URL
self.add_new_tab(QUrl("https://www.google.com"), "Homepage")
self.show()
def add_new_tab(self, qurl=None, label="Blank"):
if qurl is None:
qurl = QUrl('')
# Create a new QWebEngineView instance
browser = QWebEngineView()
browser.setUrl(qurl)
browser.createWindow = self.handle_new_window
# Add the new tab to the tab widget
i = self.tabs.addTab(browser, label)
self.tabs.setCurrentIndex(i)
def handle_new_window(self, _type):
new_tab = QWebEngineView()
new_tab.setUrl(self.sender().url()) # Use the sender's URL for the new tab
new_tab.createWindow = self.handle_new_window
# Add the new tab
self.add_new_tab(new_tab.url(), "New Tab")
return new_tab
def close_current_tab(self, i):
if self.tabs.count() < 2:
return
self.tabs.removeTab(i)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Browser()
sys.exit(app.exec_())
Is there a newer version available .
Is there a webview2 conversion to py?
Thanks for your Help…