Quantcast
Channel: froglogic
Viewing all articles
Browse latest Browse all 398

Squish tip of the week: Resizing a docked window

$
0
0

Resizing a docked window isn’t always as simple as it may seem.
Docked windows often change height and width as well as their docked location. The control or widget can also be more complex, not resizing with a simple MouseDrag used with non-docked windows.

The example below illustrates how to resize a docked window when working with the Qt Widget QDockWidget:

# 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
 
def main():
    startApplication("mainwindow")
 
    dockToResize = waitForObject(":Qt Main Window Demo.White Dock Widget [*]_ColorSwatch")
 
    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)

For more information, and a more extensive example, see Article – Resizing Docked Windows (QDockWidget)


Viewing all articles
Browse latest Browse all 398

Trending Articles