0

After upgrading to PyQt6, pageActions are now shown as text instead of icons. How do I get them to show as icons again? Is it possible to define custom icons instead?

Code to reproduce is given below.

import sys
# pageAction with icons
from PyQt5.QtWidgets import QWidget,QToolBar,QVBoxLayout,QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView,QWebEnginePage

# pageAction with text
# from PyQt6.QtWidgets import QWidget,QToolBar, QVBoxLayout, QApplication
# from PyQt6.QtWebEngineWidgets import QWebEngineView
# from PyQt6.QtWebEngineCore import QWebEnginePage
        
class Example(QWidget):

    def __init__(self):
        super().__init__()
        vbox = QVBoxLayout()
        self.setLayout(vbox)
        self.webEngineView = QWebEngineView()
        self.toolBar = QToolBar()
        self.toolBar.addAction(self.webEngineView.pageAction(QWebEnginePage.WebAction.Back))
        vbox.addWidget(self.toolBar)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    ex.show()
    sys.exit(app.exec())

output with icon or text

dukeeloo
  • 161
  • 7
  • `pageAction()` returns a QAction, did you try to access its [`icon`](https://doc.qt.io/qt-6/qaction.html#icon-prop) property? – musicamante Nov 19 '22 at 15:56
  • Yes. The following has no effect. backPage = QWebEnginePage.WebAction.Back; backPage.icon = QIcon('icon.png'); self.toolBar.addAction(self.webEngineView.pageAction(backPage )) – dukeeloo Nov 19 '22 at 18:40
  • Read the documentation carefully: if you want to set the icon, you must use the *access function* `setIcon()`. – musicamante Nov 19 '22 at 19:09
  • I did not see a reference to this function in the documentation at https://doc.qt.io/qt-6/qwebengineview.html#pageAction When I try to use it I get AttributeError: 'WebAction' object has no attribute 'setIcon' – dukeeloo Nov 19 '22 at 19:14
  • Because that documentation is about QWebEngineView, it doesn't cover *any* type that each function returns, you must read the relative documentation, which I also specifically linked in my first comment. – musicamante Nov 19 '22 at 19:16
  • Yes i get it now. I have to use setIcon on the pageAction. Thank you! – dukeeloo Nov 19 '22 at 19:18

0 Answers0