Issue
from PySide.QtGui import *
import sys
app = QApplication(sys.argv)
layout = QHBoxLayout()
print issubclass(type(layout), QWidget)
# Layout is not a kind of QWidget
window = QWidget()
window.resize(500, 500)
window.show()
window.setLayout(layout)
butt = QPushButton("asdf", parent = None)
butt.resize(100, 100)
butt.show()
layout.addWidget(butt)
print butt.parent()
app.exec_()
The parent object of butt
is window
in fact.
But I haven't set its parent to window
explicitly.
Can I say that the Layout Object has some side effects which may
set the added widget's parent to the container that it applied to?
Solution
Yes.
When you use a layout, you do not need to pass a parent when constructing the child widgets. The layout will automatically reparent the widgets (using QWidget::setParent()) so that they are children of the widget on which the layout is installed.
Note: Widgets in a layout are children of the widget on which the layout is installed, not of the layout itself. Widgets can only have other widgets as parent, not layouts.
Answered By - Avaris
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.