簡體   English   中英

pyQt QLayout問題

[英]pyQt QLayout issue

這讓我有些瘋狂。 希望有人可以幫我解決這個問題。 運行以下代碼將導致第一個打印語句是一個列表,其中包含一個元素QVBoxLayout對象。 我設置兩個對象進行layout為什么我只能得到一個?

第二個print語句給出兩個對象QHBoxLayoutQPushButton QPushButton不是layout的孩子嗎?

我希望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_())

我想文檔中的注釋足夠清楚地解釋了這一點:

注意:布局中的窗口小部件是其上安裝了布局的窗口小部件的子級,而不是布局本身。 小部件只能將其他小部件作為父級,而不能將其作為布局。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM