| 7 | |
| 8 | # Define the main window class |
| 9 | class MainWindow(QMainWindow): |
| 10 | def __init__(self): |
| 11 | super(MainWindow, self).__init__() |
| 12 | |
| 13 | # Create a QWebEngineView widget |
| 14 | self.browser = QWebEngineView() |
| 15 | self.browser.setUrl(QUrl("http://www.google.com")) |
| 16 | self.setCentralWidget(self.browser) |
| 17 | |
| 18 | # Show the window maximized |
| 19 | self.showMaximized() |
| 20 | |
| 21 | # Create a navigation toolbar |
| 22 | navbar = QToolBar() |
| 23 | navbar.adjustSize() |
| 24 | self.addToolBar(navbar) |
| 25 | |
| 26 | # Add a back button to the toolbar |
| 27 | back_btn = QAction("⮜", self) |
| 28 | back_btn.triggered.connect(self.browser.back) |
| 29 | navbar.addAction(back_btn) |
| 30 | |
| 31 | # Add a forward button to the toolbar |
| 32 | forward_btn = QAction("⮞", self) |
| 33 | forward_btn.triggered.connect(self.browser.forward) |
| 34 | navbar.addAction(forward_btn) |
| 35 | |
| 36 | # Add a reload button to the toolbar |
| 37 | reload_btn = QAction("⟳", self) |
| 38 | reload_btn.triggered.connect(self.browser.reload) |
| 39 | navbar.addAction(reload_btn) |
| 40 | |
| 41 | # Add a URL bar to the toolbar |
| 42 | self.url_bar = QLineEdit() |
| 43 | self.url_bar.returnPressed.connect(self.open_url) |
| 44 | navbar.addWidget(self.url_bar) |
| 45 | |
| 46 | # Update the URL bar when the browser URL changes |
| 47 | self.browser.urlChanged.connect(self.update_url) |
| 48 | |
| 49 | # Load the URL entered in the URL bar |
| 50 | def open_url(self): |
| 51 | url = self.url_bar.text() |
| 52 | self.browser.setUrl(QUrl(url)) |
| 53 | |
| 54 | # Update the URL bar when the browser URL changes |
| 55 | def update_url(self, q): |
| 56 | self.url_bar.setText(q.toString()) |
| 57 | |
| 58 | |
| 59 | # Create the application and main window |