Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How to open hyperlink with target=“_blank” in PyQt5

from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets

class WebEnginePage(QtWebEngineWidgets.QWebEnginePage):
    def createWindow(self, _type):
        page = WebEnginePage(self)
        page.urlChanged.connect(self.on_url_changed)
        return page

    @QtCore.pyqtSlot(QtCore.QUrl)
    def on_url_changed(self, url):
        page = self.sender()
        self.setUrl(url)
        page.deleteLater()

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)

        self.browser = QtWebEngineWidgets.QWebEngineView()
        page = WebEnginePage(self.browser)
        self.browser.setPage(page)
        self.browser.load(QtCore.QUrl("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_a_target"))
        self.setCentralWidget(self.browser)

if __name__ == '__main__':
    import sys
    app = QtWidgets.QApplication(sys.argv)
    w = MainWindow()
    w.showMaximized()
    sys.exit(app.exec_())
Comment

PREVIOUS NEXT
Code Example
Python :: idwt pywt 
Python :: how to make commas appear in integers in terminal python 
Python :: if query empty print python 
Python :: how to find all the installed packages in python 
Python :: use colabs gpu locally 
Python :: python text to speech 
Python :: cannot import name Glib 
Python :: python args description multiple lines 
Python :: cache in django 
Python :: how to store a int value in django sessions 
Python :: os get directory from string 
Python :: multiplication table with three lines of code in python 
Python :: download pyautogui 
Python :: Get the first item from an iterable that matches a condition 
Python :: geopandas españa map 
Python :: stitch two dictionary python 
Python :: py regex if .jpg 
Python :: wie printe ich in python 
Python :: python for comparing url path 
Python :: Django Give normal user privileges using python shell 
Python :: MyTestCase 
Python :: loess dataframe 
Python :: azure functions read only file system 
Python :: Adam RMSprop Adagrad. 
Python :: discord.py find user by name 
Python :: create a django and react readonly web app 
Python :: qiskit setup 
Python :: view back of list in python 
Python :: turtule code for digital clock 
Python :: mumtiply to matrices python 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =