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))
詳細な説明
Containerは、アイテムの動的な追加や削除を可能にする、コンテナ型のユーザーインターフェースコントロールの基底型です。
コンテナの使用方法
通常、項目はコンテナの子要素として静的に宣言されますが、add 、insert 、move 、およびremove を使用して、項目を動的に追加することも可能です。コンテナ内の項目には、itemAt() またはcontentChildren を使用してアクセスできます。
ほとんどのコンテナには、「現在の」アイテムという概念があります。現在のアイテムはcurrentIndex プロパティによって指定され、読み取り専用のcurrentItem プロパティを使用してアクセスできます。
次の例は、Containerの具体的な実装の一つである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
}コンテナの実装
Containerはデフォルトの視覚化機能を提供しません。これは、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
}
}ページ項目のサイズが手動で設定されている点に注目してください。これは、この例では視覚的なレイアウトについて何の前提も設けていない単純な Container を使用しているためです。通常、SwipeView やTabBar といった具体的な Container 実装では、項目のサイズを指定する必要はありません。
「コンテナ・コントロール」も参照してください 。
プロパティのドキュメント
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()
コンテナの現在のインデックスを1減らします。
このメソッドを呼び出すことで、既存のcurrentIndex バインディングを破ることなく、現在のインデックスを変更できます。
このメソッドは、QtQuick.Controls 2.1 (Qt 5.8) で導入されました。
「 currentIndex 」および「Managing the Current Index 」も参照してください 。
[since QtQuick.Controls 2.1 (Qt 5.8)] void incrementCurrentIndex()
コンテナの現在のインデックスを1増やします。
このメソッドを呼び出すことで、既存の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 で1つ分移動させ、to でさらに1つ分移動させます。
[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.