2012-02-18 64 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