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

fix type errors when rendering into a png #617

Closed
wants to merge 1 commit into from

Conversation

pschwientek
Copy link

the dimension conversion calculations yield float values but QImage expects int in constructor as well as .setDotsPerMeterX()

a quick fix is casting to int() but there are probably better ways

the dimension conversion calculations yield float values but QImage expects int in constructor as well as `.setDotsPerMeterX()

a quick fix is casting to int() but there are probably better ways
@shvenkat
Copy link

@pschwientek : Thanks for the PR! This worked for me with Python 3.10.2 and the following versions. I suggest also fixing the same issue for SVG, i.e.

--- a/treeview/main.py
+++ b/treeview/main.py
@@ -682,7 +682,7 @@
     if ext == "SVG":
         svg = QSvgGenerator()
         targetRect = QRectF(0, 0, w, h)
-        svg.setSize(QSize(w, h))
+        svg.setSize(QSize(int(round(w)), int(round(h))))
         svg.setViewBox(targetRect)
         svg.setTitle("Generated with ETE http://etetoolkit.org")
         svg.setDescription("Generated with ETE http://etetoolkit.org")
@@ -749,10 +749,10 @@
         scene.render(pp, targetRect, scene.sceneRect(), ratio_mode)
     else:
         targetRect = QRectF(0, 0, w, h)
-        ii= QImage(w, h, QImage.Format_ARGB32)
+        ii= QImage(int(round(w)), int(round(h)), QImage.Format_ARGB32)
         ii.fill(QColor(Qt.white).rgb())
-        ii.setDotsPerMeterX(dpi / 0.0254) # Convert inches to meters
-        ii.setDotsPerMeterY(dpi / 0.0254)
+        ii.setDotsPerMeterX(int(round(dpi / 0.0254))) # Convert inches to meters
+        ii.setDotsPerMeterY(int(round(dpi / 0.0254)))
         pp = QPainter(ii)
         pp.setRenderHint(QPainter.Antialiasing)
         pp.setRenderHint(QPainter.TextAntialiasing)

This works with:

Python 3.10.2
ete3                          3.1.2
PyQt5                         5.15.6
PyQt5-Qt5                     5.15.2
PyQt5-sip                     12.9.0

@KennethVrb
Copy link

I have come across the same issue and looking at your pull request i believe if you would just fix w and h variables after line 662 you will need even need to fix the dpi variable

jhcepas added a commit that referenced this pull request May 1, 2023
…ttps://www.riverbankcomputing.com/static/Docs/PyQt5/incompatibilities.html\#pyqt-v5-12. Setting PyQt5.sip.enableoverflowchecking(False) had no effect, so many calls to drawing directives have been reviewed. closes #684 #667 #617 #635
@jhcepas
Copy link
Member

jhcepas commented May 1, 2023

fixed in 71d0d3b

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

Successfully merging this pull request may close these issues.

4 participants