2012-02-18 45 views
0

这让我有点疯狂。希望有人能为我解决这个问题。运行以下代码会导致第一个打印语句是一个包含QVBoxLayout对象的元素的列表。我将两个对象设置为layout为什么我只能得到一个?pyQt QLayout问题

第二个打印语句给出两个对象QHBoxLayoutQPushButton。是不是QPushButtonlayout的子女?

我希望layout.children()给我两个对象QPushButtonQVBoxLayoutself.children()给我一个对象QHBoxLayout。我错过了什么?

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_()) 

回答

2

我想从documentation的说明解释这显然不够:

注:小部件的布局是在其上安装的,而不是布局本身的 布局小部件的孩子。小部件只能有 其他小部件作为父项,而不是布局。

+0

看起来像PySide的文档是缺乏一点。感谢您的链接。 – Jeff 2012-02-18 04:44:54