Container QML Type
コンテナに共通する機能を提供する抽象的な基本型。詳細...
| Import Statement: | import QtQuick.Controls |
| Inherits: | |
| Inherited By: | DialogButtonBox, MenuBar, SplitView, SwipeView, and TabBar |
プロパティ
- contentChildren : list<Item>
- contentData : list<QtObject>
- contentHeight : real
(since QtQuick.Controls 2.5 (Qt 5.12)) - contentModel : model
- contentWidth : real
(since QtQuick.Controls 2.5 (Qt 5.12)) - count : int
- currentIndex : int
- currentItem : Item
方法
- void addItem(Item item)
- void decrementCurrentIndex()
(since QtQuick.Controls 2.1 (Qt 5.8)) - void incrementCurrentIndex()
(since QtQuick.Controls 2.1 (Qt 5.8)) - void insertItem(int index, Item item)
- Item itemAt(int index)
- void moveItem(int from, int to)
- void removeItem(Item item)
(since QtQuick.Controls 2.3 (Qt 5.10)) - void setCurrentIndex(int index)
- Item takeItem(int index)
(since QtQuick.Controls 2.3 (Qt 5.10))
詳細説明
コンテナは、アイテムの動的な挿入と削除を可能にするコンテナのようなユーザーインターフェイスコントロールの基本型です。
コンテナの使用
通常、アイテムはコンテナの子として静的に宣言されますが、add 、insert 、move 、remove アイテムを動的に宣言することも可能です。コンテナ内のアイテムには、itemAt() またはcontentChildren を使用してアクセスできます。
ほとんどのコンテナには「カレント」アイテムの概念がある。現在のアイテムはcurrentIndex プロパティで指定され、読み取り専用のcurrentItem プロパティを使ってアクセスすることができます。
次の例では、コンテナの具体的な実装の1つであるTabBar へのアイテムの動的挿入を示します。
Row { TabBar { id: tabBar currentIndex: 0 width: parent.width - addButton.width TabButton { text: "TabButton" } } Component { id: tabButton TabButton { text: "TabButton" } } Button { id: addButton text: "+" flat: true onClicked: { tabBar.addItem(tabButton.createObject(tabBar)) console.log("added:", tabBar.itemAt(tabBar.count - 1)) } } }
現在のインデックスの管理
TabBar やSwipeView のような複数のコンテナを一緒に使用する場合、それらのcurrentIndex プロパティを互いにバインドすることで、同期を保つことができます。ユーザーがどちらかのコンテナを操作すると、そのコンテナのカレント・インデックスの変更がもう一方のコンテナに自動的に伝搬する。
ただし、JavaScriptでcurrentIndex の値を代入すると、それぞれのバインディングが削除されることに注意してください。バインディングを保持するには、以下のメソッドを使用して現在のインデックスを変更します:
TabBar {
id: tabBar
currentIndex: swipeView.currentIndex
}
SwipeView {
id: swipeView
currentIndex: tabBar.currentIndex
}
Button {
text: qsTr("Home")
onClicked: swipeView.setCurrentIndex(0)
enabled: swipeView.currentIndex != 0
}
Button {
text: qsTr("Previous")
onClicked: swipeView.decrementCurrentIndex()
enabled: swipeView.currentIndex > 0
}
Button {
text: qsTr("Next")
onClicked: swipeView.incrementCurrentIndex()
enabled: swipeView.currentIndex < swipeView.count - 1
}コンテナの実装
コンテナはデフォルトの視覚化を提供しません。SwipeView やTabBar のようなコンテナを実装するために使用されます。カスタム・コンテナを実装する場合、API の最も重要な部分はcontentModel です。これは、アイテム・ビューとリピータのオブジェクト・モデルとして使用できる方法で、含まれるアイテムを提供します。
Container { id: container contentItem: ListView { model: container.contentModel snapMode: ListView.SnapOneItem orientation: ListView.Horizontal } Text { text: "Page 1" width: container.width height: container.height } Text { text: "Page 2" width: container.width height: container.height } }
ページアイテムのサイズが手作業で設定されていることに注目してください。これは、この例では、視覚的なレイアウトを仮定しない、プレーンなコンテナを使用しているためです。通常、SwipeView やTabBar のような具体的な Container の実装では、アイテムのサイズを指定する必要はありません。
Container Controlsも参照してください 。
プロパティのドキュメント
contentChildren : list<Item>
このプロパティはコンテナの子のリストを保持する。
このリストには、コンテナの子としてQMLで宣言された全てのアイテムと、addItem()メソッドやinsertItem()メソッドを使って動的に追加・挿入されたアイテムが含まれます。
注: contentData とは異なり、contentChildren には視覚的でない QML オブジェクトは含まれません。アイテムが挿入されたり、移動されたりすると、順序が入れ替わります。
Item::children およびcontentDataも参照して ください。
contentData : list<QtObject> [default]
このプロパティはコンテンツデータのリストを保持する。
このリストには、コンテナの子オブジェクトとしてQMLで宣言されたすべてのオブジェクトと、addItem ()、insertItem ()メソッドを用いて動的に追加・挿入されたアイテムが含まれます。
注意: contentChildren とは異なり、contentData には視覚的でない QML オブジェクトも含まれます。アイテムが挿入されたり移動されたりしても、並び替えは行われません。
Item::data およびcontentChildrenも参照して ください。
contentHeight : real [since QtQuick.Controls 2.5 (Qt 5.12)]
このプロパティはコンテンツの高さを保持する。コンテナの暗黙の高さの合計を計算するために使用される。
明示的にオーバーライドされない限り、コンテンツの高さはコンテナ内のアイテムの暗黙の高さに基づいて自動的に計算されます。
このプロパティは、QtQuick.Controls 2.5(Qt 5.12)で導入されました。
contentWidthも参照してください 。
contentModel : model [read-only]
このプロパティは、アイテムのコンテンツモデルを保持する。
コンテンツモデルは視覚化のために提供される。コンテナの内容を提示するコンテンツアイテムにモデルとして割り当てることができる。
contentData およびcontentChildrenも参照のこと 。
contentWidth : real [since QtQuick.Controls 2.5 (Qt 5.12)]
このプロパティはコンテンツの幅を保持する。コンテナの暗黙の幅の合計を計算するために使用される。
明示的にオーバーライドされない限り、コンテナ内のアイテムの暗黙の幅に基づいてコンテナの幅が自動的に計算されます。
このプロパティは、QtQuick.Controls 2.5(Qt 5.12)で導入されました。
contentHeightも参照してください 。
count : int [read-only]
このプロパティは、アイテムの数を保持する。
currentIndex : int
このプロパティは、現在のアイテムのインデックスを保持する。
currentItem およびManaging the Current Indexも参照のこと 。
currentItem : Item [read-only]
このプロパティは現在の項目を保持する。
currentIndexも参照してください 。
メソッド・ドキュメント
void addItem(Item item)
item を追加する。
[since QtQuick.Controls 2.1 (Qt 5.8)] void decrementCurrentIndex()
コンテナの現在のインデックスを減らします。
このメソッドを呼び出すと、既存のcurrentIndex バインディングを壊すことなく、現在のインデックスを変更できます。
このメソッドは QtQuick.Controls 2.1 (Qt 5.8) で導入されました。
currentIndex およびManaging the Current Indexも参照してください 。
[since QtQuick.Controls 2.1 (Qt 5.8)] void incrementCurrentIndex()
コンテナの現在のインデックスをインクリメントする。
このメソッドを呼び出すと、既存のcurrentIndex バインディングを壊すことなく、現在のインデックスを変更できます。
このメソッドは QtQuick.Controls 2.1 (Qt 5.8) で導入されました。
currentIndex およびManaging the Current Indexも参照して ください。
void insertItem(int index, Item item)
index にitem を挿入する。
Item itemAt(int index)
アイテムが存在しない場合、index 、またはnull にアイテムを返す。
void moveItem(int from, int to)
アイテムfrom あるインデックスto 別のインデックスに移動する。
[since QtQuick.Controls 2.3 (Qt 5.10)] void removeItem(Item item)
指定されたitem を削除・破棄します。
このメソッドは QtQuick.Controls 2.3 (Qt 5.10) で導入されました。
void setCurrentIndex(int index)
コンテナの現在のindex を設定する。
このメソッドを呼び出すと、既存のcurrentIndex バインディングを壊すことなく、特定のカレントインデックスを設定できます。
currentIndex およびManaging the Current Indexも参照してください 。
[since QtQuick.Controls 2.3 (Qt 5.10)] Item takeItem(int index)
index にあるアイテムを削除して返す。
注意: アイテムの所有権は呼び出し元に移ります。
このメソッドは QtQuick.Controls 2.3 (Qt 5.10) で導入されました。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.