How to fix the width scale ratio of central widget to mainwindow which contains dockwidgets
-
Hello everyone !
I have a mainwindow with some dockwidgets docked at the right side of it. And I also place a central widget in mainwindow. I want to keep the central widget's width as a fixed scale ratio to mainwindow's width, and the dockwidgets at right side occupy the remained width.I found that there is a property in central widget's layout with name of 'layoutStretch', but it seemed that could not make central widget work as I wish.
Could anyone tell me some instruction ? thanks a lot!
-
I don't have a ready-made solution for you, but I can tell you at least that:
layoutStretch
is the wrong place to look for - this is a technique that allows you to set 'weights' for elements that are handled by the same layout (as far as I understand)- I'd start looking for the
resizeEvent()
member of theQMainWindow
class (it is defined inQWidget
) - reimplement that function and have it resize the central widget based on your desired scale ratio
-
@Jakob
Thanks, Mr. Jakob. I'd tried to resize central widget in resizeEvent(), I found it seemed that setting the geometry of the central widget's layout could work, but not worked good completely. One of the problems is : the docked widgets's width do not change synchronously, this problem cause spacing or overlapping appeares between central widget and docking widgets while resizing mainwindow.I thought maybe I should call 'updateGeometry' for every docked widget, but I have not enough time to verify this guess. would you please tell me?
Well, there is another question about dockwidget and mainwindow:
I found there was an internal splitter between central widget and docking widgets, and if I pressed mouse left button and pulled it to another position, the docking widgets's width would be fixed and could only be changed by pulling the splitter. This problem makes my purpose to unreached too. How can I work around it?