Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 506520f

Browse files
authored
Merge pull request #9131 from tacaswell/fix_qt_resizing
FIX: prevent the canvas from jump sizes due to DPI changes
2 parents 8a244e4 + 28b37c1 commit 506520f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/matplotlib/backends/backend_qt5.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,7 @@ def __init__(self, canvas, num):
605605
# requested size:
606606
cs = canvas.sizeHint()
607607
sbs = self.window.statusBar().sizeHint()
608-
self._status_and_tool_height = tbs_height + sbs.height()
609-
height = cs.height() + self._status_and_tool_height
608+
height = cs.height() + tbs_height + sbs.height()
610609
self.window.resize(cs.width(), height)
611610

612611
self.window.setCentralWidget(self.canvas)
@@ -654,8 +653,11 @@ def _get_toolmanager(self):
654653
return toolmanager
655654

656655
def resize(self, width, height):
657-
'set the canvas size in pixels'
658-
self.window.resize(width, height + self._status_and_tool_height)
656+
# these are Qt methods so they return sizes in 'virtual' pixels
657+
# so we do not need to worry about dpi scaling here.
658+
extra_width = self.window.width() - self.canvas.width()
659+
extra_height = self.window.height() - self.canvas.height()
660+
self.window.resize(width+extra_width, height+extra_height)
659661

660662
def show(self):
661663
self.window.show()

0 commit comments

Comments
 (0)