Overview¶
Docked windows, for example using the QDockWidget control, do not respond to MouseDrag or resizing the same as non-docked windows or widgets.
This article demonstrates how to resize a docked window using two different approaches (example included):
Resize Docked Window Using Mouse: Creating a MouseDrag action by combining MousePress and MouseRelease¶
# About Example
# Supply specific QDockWidget's symbolic or real name (in this sample application QDockWidget is ColorSwatch)
# change_* functions take three parameters: QDockWidget as o, resize value as xdiff, snooze in seconds (optional) as snoozeFactor
import names
def main():
startApplication("mainwindow")
dockToResize = waitForObject({"name": "Dock Widget", "type": "ColorSwatch", "window": names.Main_Window_Demo_MainWindow})
change_height_on_top(dockToResize, -20)
change_height_on_top(dockToResize, 20)
change_height_on_bottom(dockToResize, -20)
change_height_on_bottom(dockToResize, 20)
change_width_on_left(dockToResize, -20)
change_width_on_left(dockToResize, 20)
change_width_on_right(dockToResize, 20)
change_width_on_right(dockToResize, -20)
def change_height_on_top(o, xdiff, snoozeFactor = 0):
snooze(snoozeFactor)
mousePress(o, 50, -2, MouseButton.LeftButton)
start = 0
end = xdiff
step = 1
if xdiff < 0:
step = -1
for i in range(start, end, step):
mouseMove(o, 50, -2 + i)
mouseRelease()
snooze(snoozeFactor)
def change_height_on_bottom(o, xdiff, snoozeFactor = 0):
snooze(snoozeFactor)
mousePress(o, 50, o.height + 2, MouseButton.LeftButton)
start = 0
end = xdiff
step = 1
if xdiff < 0:
step = -1
for i in range(start, end, step):
mouseMove(o, 50, o.height + 2 + i)
mouseRelease()
snooze(snoozeFactor)
def change_width_on_left(o, xdiff, snoozeFactor = 0):
snooze(snoozeFactor)
mousePress(o, -3, 50, MouseButton.LeftButton)
start = 0
end = xdiff
step = 1
if xdiff < 0:
step = -1
for i in range(start, end, step):
mouseMove(o, -3 + i, 50)
mouseRelease()
snooze(snoozeFactor)
def change_width_on_right(o, xdiff, snoozeFactor = 0):
snooze(snoozeFactor)
mousePress(o, o.width + 3, 50, MouseButton.LeftButton)
start = 0
end = xdiff
step = 1
if xdiff < 0:
step = -1
for i in range(start, end, step):
mouseMove(o, o.width + 3 + i, 50)
mouseRelease()
snooze(snoozeFactor)
Resize Docked Window Using QWidget.resize()¶
import names
def main():
startApplication("mainwindow")
myDockedWindow = waitForObject(names.Main_Window_Demo_White_DockWidget_ColorSwatch)
myDockedWindow.resize(500, 600)
Resize Docked Window (and maintain Dock min and max Height and Width)¶
import names
def main():
startApplication("mainwindow")
resizeDockWidget(waitForObject(names.Main_Window_Demo_White_DockWidget_ColorSwatch), 500, 600)
def resizeDockWidget(widget, newWidth, newHeight):
originalSize = widget.size
originalMin = widget.minimumSize
originalMax = widget.maximumSize
widget.resize(newWidth,newHeight)
if newWidth != originalSize.width:
if widget.width > newWidth:
widget.setMaximumWidth(newWidth)
else:
widget.setMinimumWidth(newWidth)
if newHeight != originalSize.height:
if widget.height > newHeight:
widget.setMaximumHeight(newHeight)
else:
widget.setMinimumHeight(newHeight)
widget.setMinimumWidth(originalMin.width)
widget.setMinimumHeight(originalMin.height)
widget.setMaximumWidth(originalMax.width)
widget.setMaximumHeight(originalMax.height)