Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'QWebEngineView' object has no attribute 'print_' #1

Open
Pagliacii opened this issue Feb 26, 2018 · 3 comments
Open

Comments

@Pagliacii
Copy link

https://github.com/mfitzp/15-minute-apps/blob/b99eb330310fe7302ead39473ef0d34cccb3d12d/browser/browser.py#L168

image

OS: win10 x64
Python: 3.5.4 x64
PyQt: 5.10.0

@Pagliacii
Copy link
Author

https://github.com/mfitzp/15-minute-apps/blob/b99eb330310fe7302ead39473ef0d34cccb3d12d/browser_tabbed/browser_tabbed.py#L217

Traceback (most recent call last):
  File "browser_tabbed.py", line 217, in print_page
    dlg.paintRequested.connect(self.browser.print_)
AttributeError: 'MainWindow' object has no attribute 'browser'

@richlysakowski
Copy link

richlysakowski commented Mar 18, 2021

I get the same error as above. The error show up in the console log when the user selects the File submenu "File... Print..."

0-MyProjects/PyQt5-15mins-apps/browser_tabbed')
Traceback (most recent call last):

File "C:\Users...!0-MyProjects\PyQt5-15mins-apps\browser_tabbed\browser_tabbed-RSL-WIP.py", line 226, in print_page
dlg.paintRequested.connect(self.browser.print_)

AttributeError: 'MainWindow' object has no attribute 'browser

Should this dlg.paintRequested.connect(self.browser.print_) refer to QPrintPreviewDialog() or should it refer to print_action instantiated earlier, i.e., print_action.triggered.connect(self.print_page) ?

Why is it using the paintRequested attribute for the .connect() signal, instead of actually invoking the QPrintPreviewDialog box?

Please suggest a fix for this, and clarify the fix with an explanation?

Thank you.

Richard

@Pagliacii
Copy link
Author

Pagliacii commented Mar 19, 2021

AttributeError: 'MainWindow' object has no attribute 'browser

@richdevboston You can fix this by adding the method below into the browser_tabbed.MainWindow class.

def handle_paint_request(self, printer):
    painter = QPainter(printer)
    browser = self.tabs.currentWidget()
    painter.setViewport(browser.rect())
    painter.setWindow(browser.rect())
    browser.render(painter)
    painter.end()

And change the print_page method:

def print_page(self):
    dlg = QPrintPreviewDialog()
-   dlg.paintRequested.connect(self.browser.print_)
+   dlg.paintRequested.connect(self.handle_paint_request)
    dlg.exec_()

FYI, these links below can help you if something wrong:

To fix browser.MainWindow.print_page method, the handle_paint_request must be changed a little:

def handle_paint_request(self, printer):
    painter = QPainter(printer)
-   browser = self.tabs.currentWidget()
-   painter.setViewport(browser.rect())
-   painter.setWindow(browser.rect())
-   browser.render(painter)
+   painter.setViewport(self.browser.rect())
+   painter.setWindow(self.browser.rect())
+   self.browser.render(painter)
    painter.end()

HTH
Jason

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants