Issue
I'm little confusing meaning of widgets instance creation in PyQt.
Seems QWidget(self) can create a widget. But what's the meaning of QWidget(instance name)?
For exmaple,
grid_layout = QGridLayout(self)
test_label = QWidget(grid_layout)
I know test_label created inherited from gridlayout. But what's the meaning during program meaning? Is that meaning test_label widget is under grid_layout?
Solution
For many of the widgets when the signature is just a single parameter like in both of your examples, the argument given sets the created widget/layouts parent.
So in your first example, using self
as the argument means that the parent of the QGridLayout and the widget that the layout will be applied to is whatever widget self
is.
In the second example you are setting the parent of QWidget to be the widget represented by it's argument. A QWidget with no parent becomes a new window, when set with a parent then the widget becomes a child window within the parent widget.
Neither one are inheriting anything. Inheritance only occurs during Subclassing.
Answered By - Alexander
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.