techartorg / bqt

A Blender add-on to support & manage Qt Widgets in Blender (PySide2)
https://github.com/techartorg/bqt/wiki
Mozilla Public License 2.0
161 stars 23 forks source link

first time qt window size is too small #72

Closed hannesdelbeke closed 1 year ago

hannesdelbeke commented 1 year ago

when blender is wrapped in qt for the first time the window is too small

we can get the size from blender window before we wrap it, and the set the wrapped window to this size.

hannesdelbeke commented 1 year ago

see private note "Blender window size"

import ctypes
from bqt.blender_applications.win32_blender_application import get_process_hwnds
from ctypes import wintypes  
user32 = ctypes.windll.user32

process_windows = get_process_hwnds()
for win in process_windows:  
    # get height and width  
    rect = wintypes.RECT()  
    user32.GetWindowRect(win.hwnd, ctypes.byref(rect))  
    height = rect.bottom - rect.top  
    width = rect.right - rect.left  
    print(height, width)

import bpy  
print("height bpy", bpy.context.window_manager.windows[0].height, "width", bpy.context.window_manager.windows[0].width)
type height width
main window user32 2065 2124
main window bpy 2009 2102
main window diff 56 22

when qt wrapped window is 0 height. bpy returns 0 but qt returns 56 height. likely the title bar height measure with powertoys returns 28 pixels height windows, 150% scale on 3840 x 2160px

hannesdelbeke commented 1 year ago
hannesdelbeke commented 1 year ago

turns out we didnt need the fancy ctypes stuff. we can just get size and pos from the blender window with bpy works on all OS with no extra effort for us