Comments (3)
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'
from pythonguis-examples.
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
from pythonguis-examples.
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
from pythonguis-examples.
Related Issues (20)
- notes requires sqlalchemy, but not in requirements.txt
- Currency: legacy api.fixer.io HOT 5
- Please mentions pyqt5 or pyqt4 HOT 2
- No Data is being pulled from the Api.
- The issue of paste screenshot picture in the wordprocessor
- for calculator, is sip needed? HOT 1
- 15 min pyQt
- New tab and view pdf file
- Getting error saying Segmentation fault (core dumped) HOT 1
- C
- Browser crashes when saving file HOT 1
- The tabbed browser can't open the target="_blank" link. Is there any way to solve it? thanks
- Games
- 扫雷游戏中为什么我无法显示图片,我的pyqt5在anaconda环境中似乎一直存在这个问题 HOT 2
- Found bugs
- 原计算器不支持小数点计算
- calculator: input integer overflows when > 0x7FFFFFFF(or 2147483647)
- The browser sample can't open the target="_blank" link. Is there any way to solve it?thanks HOT 1
- Mozarella Ashbadger: Proxy Connection
- Pycharm - PyQt5.QtCore ImportError: DLL load failed: %1 ist keine zulässige Win32-Anwendung.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pythonguis-examples.