2014-11-21 32 views
1

我正在嘗試修改Gallery示例。我想在TabView下加Button。於是,我把TabViewButtonColumnLayout,這裏是代碼:ColumnLayout中的QML TabView

import QtQuick 2.3 
import QtQuick.Controls 1.2 
import QtQuick.Layouts 1.1 
import QtQuick.Controls.Styles 1.1 
import QtQuick.Window 2.0 

Window { 
    visible: true 
    title: "settings" 
    width: 600 
    height: 400 
ColumnLayout{ 
    anchors.fill: parent 
    TabView { 
     anchors.right: parent.right 
     anchors.left: parent.left 
     Tab { 
      title: "Controls" 
      Controls { } 
     } 
     Tab { 
      title: "Itemviews" 
      Controls { } 
     } 
     Tab { 
      title: "Styles" 
      Controls { } 
     } 
     Tab { 
      title: "Layouts" 
      Controls { } 
     } 
    } 

    RowLayout{ 
     anchors.right: parent.right 
     anchors.left: parent.left 
     Button{ 
      text: "ok" 
     } 
    } 
} 

} 

然而,當我調整窗口下的標籤控件okButton代表。我應該如何修復代碼?

+0

您將按鈕放在TabView下,因爲我看到了,那麼您的問題是什麼?我不能僅僅因爲udefined'Controls'來測試你的例子,但是你可能應該爲'TabView'使用'Layout.fillHeight'&'Layout.fillWidth'?但是不要忘記設置RowLayout的高度 – folibis 2014-11-21 23:16:07

+0

@folibis'Controls.qml'位於'Qt Quick Controls - Gallery'示例中。只需打開Qt創建者 - >歡迎並鍵入「圖庫」。當我調整窗口大小時,'okButton'不在'TabView'下面,而是在'TabView'上面 – lnk 2014-11-22 07:36:32

回答

1

當您定義了Layout時,添加的每個元素都可以訪問與佈局本身相關的特定屬性。這些屬性對於將元素放置在佈局覆蓋的空間內很有用。面對什麼here

因此,你應該修改ColumnLayout這樣的:

ColumnLayout { 
    anchors.fill: parent     
    TabView { 
     id:frame 
     enabled: enabledCheck.checked 
     tabPosition: controlPage.item ? controlPage.item.tabPosition : Qt.TopEdge 
     Layout.fillHeight: true   // fill the available space vertically 
     Layout.fillWidth: true    // fill the available space horizontally 
     Layout.row: 0      // item in the first row of the column 
     anchors.margins: Qt.platform.os === "osx" ? 12 : 2 
     Tab { 
      id: controlPage 
      title: "Controls" 
      Controls { } 
     } 
     Tab { 
      title: "Itemviews" 
      ModelView { } 
     } 
     Tab { 
      title: "Styles" 
      Styles { anchors.fill: parent } 
     } 
     Tab { 
      title: "Layouts" 
      Layouts { anchors.fill:parent } 
     } 
    } 

    Button { 
     text: "ok" 
     Layout.row: 1      // item in the second row of the column 
     Layout.alignment: Qt.AlignCenter // simple center the button in its spatial slot 
    } 
} 

你不需要的按鈕RowLayout。它應該放在您定義的ColumnLayout的第二行,因爲它是一個簡單的組件。在同一行上的多個元件的情況下,子佈局可能是有用的,例如,兩個或更多按鈕。

還要注意,錨定僅用於ColumnLayout「拉伸」並適合窗口。所有其他操作都通過佈局屬性執行。有關一般規則,請參閱this其他文章。

+0

當我調整窗口大小時,'okButton'被放在標籤 – lnk 2014-11-22 11:07:52

+0

的控制之上如果你把圖片的例子保持原樣,已經完成了,它不應該。如果刪除了可能的最小寬度,則取決於選項卡組件的設置。這是完全不同的問題。實際上'Controls'具有'Layout.minimumWidth:implicitWidth' ......你不能只考慮組件的佈局就調整'Window'的大小。 – BaCaRoZzo 2014-11-22 12:17:17

+0

我增加了最小寬度和高度。現在它工作正常 – lnk 2014-11-22 12:53:26