Creating a tabbed browser using PyQt5
In this article, we will see how we can create a tabbed browser using PyQt5.
Web browser is a software application for accessing information on the World Wide Web. When a user requests a web page from a particular website, the web browser retrieves the necessary content from a web server and then displays the page on the screen.
Tabbing : Adding tabs complicates the internals of the browser a bit, since there will now need to keep track of the currently active browser view, both to update UI elements (URL bar) to changing state in the currently active window and to ensure the UI events are dispatched to the correct web view.
PyQt5 is cross-platform GUI toolkit, a set of python bindings for Qt v5. One can develop an interactive desktop application with so much ease because of the tools and simplicity provided by this library. It has been installed using the command given below
pip install PyQt5
GUI Implementation steps :
1. Create a main window
2. Create a QTabWidget for tabbing, set it as central widget, make them documented and closable, below is how the tabs will look like
3. Create a status bar to show the status tips
4. Create a tool bar and add navigation button and the line edit to show the url, below is hot the tool bar will look like
Back-End Implementation Steps :
1. Add action to the QTabWidget object when double-clicked is pressed
2. Inside the double click action check if the double click is on no tab then call the open tab method
3. Inside the open tab, method create a QUrl object and the QWebEngineView object and set QUrl to it and get the index of the tab
4. Add update url action to QWebEngineView object when url is changed.
5. Inside the update, url action check if action is called by the opened tab then change the url of url bar and change cursor position
6. Add another update title action to the QWebEngineView object when loading is finished
7. Inside the update title method update the title of the window as the page title if the action is called by the open tab only
8. Add action to the tabs when the tab is changed
9. Inside the tab changed action get the url update the url inline edit and the title
10. Add actions to the navigation buttons using the build-in functions of the QWebEngineView object for reloading, back, stop and forward buttons
11. Add action to the home button and inside the action change the url to google.com
12. Add action to the line edit when the return key is pressed
13. Inside the line, edit action get the text and convert this text to the QUrl object and set the scheme if it is null and set this url to the current tab
Below is the implementation