Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Simplify the qt backend by using buffers to construct the image to be restored#27913
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
7121234
3d1ce96
391ac40
0258fb7
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2,15 +2,14 @@ | ||
Render to qt from agg. | ||
""" | ||
importnumpy as np | ||
from .qt_compat import QtGui | ||
from .backend_agg import FigureCanvasAgg | ||
from .backend_qt import _BackendQT, FigureCanvasQT | ||
from .backend_qt import ( # noqa: F401 # pylint: disable=W0611 | ||
FigureManagerQT, NavigationToolbar2QT) | ||
from ..transforms import Bbox | ||
class FigureCanvasQTAgg(FigureCanvasAgg, FigureCanvasQT): | ||
@@ -47,25 +46,19 @@ def paintEvent(self, event): | ||
right = left + width | ||
# create a buffer using the image bounding box | ||
bbox = Bbox([[left, bottom], [right, top]]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think it would work to simply do See also#23882 and the linked discourse thread. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Thanks for the linked issue, very relevant. FWIW, I'm fully in favour of removing That linked discussion was super interesting - I had assumed that there was nobody using a subset bbox for Ultimately, I think we share the same objective here... I'm guessing this is about standardising the (rasterising) renderer such that in the future we could have backends which are not renderer specific (e.g. a common implementation of a qt backend for both agg and cairo (and other potential renderers)). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I took a look at this, and you are right. I like it because it avoids extending the existing inaccessible type. It doesn't solve the fact that we do need to return more than just an image (we need the origin of the image too), but I'm confident we could remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I should say: I don't see a need for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I realised that this PR should also cover qtcairo, which has virtually the same implementation (but uses the pre-multiplied format) | ||
img =np.asarray(self.copy_from_bbox(bbox), dtype=np.uint8) | ||
# Clear the widget canvas, to avoid issues as seen in | ||
# https://github.com/matplotlib/matplotlib/issues/13012 | ||
painter.eraseRect(rect) | ||
pelson marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
qimage = QtGui.QImage( | ||
img, img.shape[1], img.shape[0], | ||
QtGui.QImage.Format.Format_RGBA8888, | ||
) | ||
qimage.setDevicePixelRatio(self.device_pixel_ratio) | ||
# set origin using original QT coordinates | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Looking at#25363 I guess this branch is never exercised anymore indeed, but the qt>=5.12 version bound doesn't seem to be documented anywhere but in that PR changelog note; perhaps it should be mentioned in dependencies.rst (even though it is already a consequence of wheel availability for py3.9)? (@oscargus) | ||
painter.drawImage(rect.topLeft(), qimage) | ||
self._draw_rect_callback(painter) | ||
finally: | ||