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

Skip to content

Commit 28b37c1

Browse files
committed
FIX: prevent the canvas from jump sizes due to DPI changes
closes #8736 thanks to @rayosborn
1 parent da06ed9 commit 28b37c1

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
@@ -509,8 +509,7 @@ def __init__(self, canvas, num):
509509
# requested size:
510510
cs = canvas.sizeHint()
511511
sbs = self.window.statusBar().sizeHint()
512-
self._status_and_tool_height = tbs_height + sbs.height()
513-
height = cs.height() + self._status_and_tool_height
512+
height = cs.height() + tbs_height + sbs.height()
514513
self.window.resize(cs.width(), height)
515514

516515
self.window.setCentralWidget(self.canvas)
@@ -554,8 +553,11 @@ def _get_toolbar(self, canvas, parent):
554553
return toolbar
555554

556555
def resize(self, width, height):
557-
'set the canvas size in pixels'
558-
self.window.resize(width, height + self._status_and_tool_height)
556+
# these are Qt methods so they return sizes in 'virtual' pixels
557+
# so we do not need to worry about dpi scaling here.
558+
extra_width = self.window.width() - self.canvas.width()
559+
extra_height = self.window.height() - self.canvas.height()
560+
self.window.resize(width+extra_width, height+extra_height)
559561

560562
def show(self):
561563
self.window.show()

0 commit comments

Comments
 (0)