Reputation: 7210
This is driving me a little crazy. Hope someone can clear this up for me. Running the following code results in the first print statement being a list with one element the QVBoxLayout
object. I set two objects to layout
why do I get only one?
The second print statement gives two objects the QHBoxLayout
and QPushButton
. Isn't QPushButton
a child of layout
?
I would expect layout.children()
to give me two objects QPushButton
and QVBoxLayout
and self.children()
to give me one object QHBoxLayout
. What am I missing?
from PySide.QtGui import *
import sys
class Main(QWidget):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
layout = QHBoxLayout(self)
layout.addWidget(QPushButton("foo"))
layout.addLayout(QVBoxLayout())
print layout.children()
print self.children()
app = QApplication([])
main = Main()
main.show()
sys.exit(app.exec_())
Upvotes: 0
Views: 1010
Reputation: 36735
I guess the note from the documentation explains this clearly enough:
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.
Upvotes: 3