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も参照してください 。
プロパティ Documentation
このプロパティは、コンテンツの子のリストを保持する。
このリストには、コンテナの子として QML で宣言されたすべてのアイテムと、それぞれaddItem() とinsertItem() メソッドを使って動的に追加または挿入されたアイテムが含まれます。
注: contentData
とは異なり、contentChildren
には視覚的でない QML オブジェクトは含まれません。アイテムが挿入されたり、移動されたりすると、順序が入れ替わります。
Item::children およびcontentDataも参照 。
このプロパティは、コンテンツデータのリストを保持する。
このリストには、コンテナの子オブジェクトとして QML で宣言されたすべてのオブジェクトと、addItem() メソッドおよびinsertItem() メソッドを用いて動的に追加または挿入されたアイテムが含まれます。
注意: contentChildren
とは異なり、contentData
には視覚的でない QML オブジェクトも含まれます。アイテムが挿入されたり移動されたりしても、並び替えは行われません。
Item::data およびcontentChildrenも参照して ください。
contentHeight : real |
このプロパティはコンテンツの高さを保持します。コンテナの暗黙的な高さの合計を計算するために使用される。
明示的にオーバーライドされない限り、コンテンツの高さは、コンテナ内のアイテムの暗黙の高さに基づいて自動的に計算されます。
このプロパティは、QtQuick.Controls 2.5(Qt 5.12)で導入されました。
contentWidthも参照してください 。
contentModel : model |
このプロパティは、アイテムのコンテンツモデルを保持します。
コンテンツ・モデルは、視覚化のために提供されます。コンテナの内容を表示するコンテント・アイテムのモデルとして割り当てることができます。
Container { id: container contentItem: ListView { model: container.contentModel } }
contentData およびcontentChildren も参照 。
contentWidth : real |
このプロパティは、コンテンツ幅を保持する。コンテナの暗黙的な幅の合計を計算するために使用される。
明示的にオーバーライドされない限り、コンテナの幅は、コンテナ内のアイテムの暗黙の幅に基づいて自動的に計算される。
このプロパティは、QtQuick.Controls 2.5(Qt 5.12)で導入されました。
contentHeightも参照してください 。
count : int |
このプロパティは、アイテムの数を保持します。
currentIndex : int |
このプロパティは、現在のアイテムのインデックスを保持します。
currentItem およびManaging the Current Index も参照して ください。
currentItem : Item |
このプロパティは現在の項目を保持します。
currentIndex も参照して ください。
メソッド・ドキュメント
void addItem(Item item) |
item を追加します。
|
コンテナの現在のインデックスを減らします。
このメソッドを呼び出すと、既存のcurrentIndex
バインディングを壊すことなく、現在のインデックスを変更できます。
このメソッドは QtQuick.Controls 2.1 (Qt 5.8) で導入されました。
currentIndex およびManaging the Current Indexも参照してください 。
|
コンテナの現在のインデックスをインクリメントする。
このメソッドを呼び出すと、既存のcurrentIndex
バインディングを壊すことなく、現在のインデックスを変更できます。
このメソッドは QtQuick.Controls 2.1 (Qt 5.8) で導入されました。
currentIndex およびManaging the Current Indexも参照してください 。
|
指定されたitem を削除・破棄します。
このメソッドは QtQuick.Controls 2.3 (Qt 5.10) で導入されました。
void setCurrentIndex(int index) |
コンテナの現在のindex を設定します。
このメソッドを呼び出すと、既存のcurrentIndex
バインディングを壊すことなく、特定の現在のインデックスを設定できます。
currentIndex およびManaging the Current Indexも参照してください 。
index にあるアイテムを削除して返す。
注意: アイテムの所有権は呼び出し元に移ります。
このメソッドは QtQuick.Controls 2.3 (Qt 5.10) で導入されました。
© 2025 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.