Is there a way to set the parent of a widget in QtDesigner?
-
I have a nested layout.
I created this layout directly in QtDesigner. But I'm weird about the parents of these widgets. For example, the parent oflabel_ok_2_2
isgroup_box_ok
. Why its parent is not its upper containerhorizontalLayout_18
? Can we get the parent information directly in QtDesigner? Can we directly set the parent of a widget in QtDesigner? I want to do so because I want to do some dynamic settings according to the children of aQLayout
.
Any help is appreciated, thanks. -
I have a nested layout.
I created this layout directly in QtDesigner. But I'm weird about the parents of these widgets. For example, the parent oflabel_ok_2_2
isgroup_box_ok
. Why its parent is not its upper containerhorizontalLayout_18
? Can we get the parent information directly in QtDesigner? Can we directly set the parent of a widget in QtDesigner? I want to do so because I want to do some dynamic settings according to the children of aQLayout
.
Any help is appreciated, thanks.@feiyuhuahuo The kinship relationship is between QWidget, that serves for memory management (for QObjects like QWidget) but it also serves for the process of creating the window or painting. There is no such relationship between layouts. The layouts are not visible elements but managers of the geometry. When a QWidget is established in a QLayout, it is established that it will be a child of the QWidget set to the layout.
That has nothing to do with QtDesigner but with the design of Qt.
horizontalLayout_18 is not a container, it is just a position and size handle.
It seems that you have an XY problem since you have an objetive : I want to do so because I want to do some dynamic settings according to the children of a QLayout but you ask for a possible solution that no one guarantees will work.
-
@eyllanesc I can't understand clearly. What is an XY problem? Anyway, I found that if I create a dialog totally by QtDesigner and then put some widgets and layouts in it, regardless of the layouts, all the widgets' parents will be the dialog itself. But I can still set their parents manually with
.setParent()
function. I just found nowhere to set parent for a widget in QtDesigner. -
@eyllanesc I can't understand clearly. What is an XY problem? Anyway, I found that if I create a dialog totally by QtDesigner and then put some widgets and layouts in it, regardless of the layouts, all the widgets' parents will be the dialog itself. But I can still set their parents manually with
.setParent()
function. I just found nowhere to set parent for a widget in QtDesigner.@feiyuhuahuo said in Is there a way to set the parent of a widget in QtDesigner?:
I just found nowhere to set parent for a widget in QtDesigner.
You wouldn't want to, it doesn't make sense. In Designer its parent is whichever widget it has been placed onto.
-
@eyllanesc I can't understand clearly. What is an XY problem? Anyway, I found that if I create a dialog totally by QtDesigner and then put some widgets and layouts in it, regardless of the layouts, all the widgets' parents will be the dialog itself. But I can still set their parents manually with
.setParent()
function. I just found nowhere to set parent for a widget in QtDesigner. -
@eyllanesc @JonB Thanks, I think I need to be more familiar with QT.