基本入力
FileDropZone ファイルドロップゾーン
ローカルファイルのドロップを受け付け、参照ボタンがクリックされたときにアプリケーションへピッカーを開くよう要求します。
サンプル
プロパティプレビューを読み込めませんでした。もう一度「プロパティプレビュー」を選択して再試行してください。

使い方
ワークスペースに追加
filesDropped はドロップされたローカル URL を通知します。browseRequested を接続してファイルピッカーを開き、ファイルの種類とサイズはアプリケーション側で確認してください。
#include <FluentQt/BasicInput.h>
using namespace fluent::basicinput;
auto* panel = new QWidget(this);
auto* layout = new QVBoxLayout(panel);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(24);
auto* drop = new FileDropZone(panel);
drop->setObjectName("fileDropZone");
drop->setDescription("Add documents, images or a ZIP archive.");
drop->setHintText("PDF, PNG, JPG, ZIP · Up to 20 MB per file");
layout->addWidget(drop);
auto* heading = new Label("Files", panel);
heading->setFluentTypography(Typography::FontRole::BodyStrong);
layout->addWidget(heading);
auto* model = new QStandardItemModel(panel);
auto addFile = [model](const QString& name, const QString& detail,
FileListView::Status state, qreal progress) {
auto* item = new QStandardItem(name);
item->setData(detail, FileListView::MetadataRole);
item->setData(state, FileListView::StatusRole);
item->setData(progress, FileListView::ProgressRole);
model->appendRow(item);
};
addFile("brand-guidelines.pdf", "2.4 MB · Ready to use", FileListView::Ready, 1.0);
addFile("product-shot.png", "3.6 / 5.8 MB · Uploading", FileListView::Uploading, 0.62);
addFile("archive.zip", "28 MB · Exceeds the 20 MB limit", FileListView::Rejected, 0.0);
auto* files = new FileListView(panel);
files->setObjectName("selectedFiles");
files->setAccessibleName("Selected files");
files->setBackgroundVisible(false);
files->setBorderVisible(false);
files->setProperty("fluentPreserveParentSurface", true);
files->viewport()->setProperty("fluentPreserveParentSurface", true);
files->setMinimumHeight(260);
files->setModel(model);
layout->addWidget(files);
QObject::connect(files, &FileListView::removeRequested, panel,
[model](const QModelIndex& index) { model->removeRow(index.row()); });
auto acceptFile = [drop, addFile](const QString& name, qint64 bytes) {
const QString suffix = QFileInfo(name).suffix().toLower();
const bool typeAllowed = QStringList{"pdf", "png", "jpg", "jpeg", "zip"}.contains(suffix);
const bool sizeAllowed = bytes <= 20 * 1024 * 1024;
if (!typeAllowed || !sizeAllowed) {
const QString reason = !typeAllowed ? "This file type is not supported."
: "Choose a file under 20 MB.";
drop->setErrorMessage(name + " · " + reason);
addFile(name, reason, FileListView::Rejected, 0.0);
return;
}
drop->clearError();
addFile(name, QString::number(bytes / (1024.0 * 1024.0), 'f', 1) + " MB · Ready to use",
FileListView::Ready, 1.0);
};
QObject::connect(drop, &FileDropZone::filesDropped, panel,
[acceptFile](const QList<QUrl>& urls) {
for (const QUrl& url : urls) {
const QFileInfo file(url.toLocalFile());
if (file.isFile())
acceptFile(file.fileName(), file.size());
}
});
QObject::connect(drop, &FileDropZone::browseRequested, panel, [panel, acceptFile]() {
platform::chooseFiles(panel, "Documents (*.pdf *.png *.jpg *.jpeg *.zip)", acceptFile);
});import fluentqt
from PySide6.QtCore import QFileInfo, Qt
from PySide6.QtGui import QStandardItem, QStandardItemModel
from PySide6.QtWidgets import QFileDialog, QVBoxLayout, QWidget
panel = QWidget()
layout = QVBoxLayout(panel)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(24)
model = QStandardItemModel(panel)
roles = fluentqt.FileListView.DataRole
states = fluentqt.FileListView.Status
def add_file(name, detail, state, progress):
item = QStandardItem(name)
item.setData(detail, roles.MetadataRole)
item.setData(state, roles.StatusRole)
item.setData(progress, roles.ProgressRole)
model.appendRow(item)
add_file("brand-guidelines.pdf", "2.4 MB · Ready to use", states.Ready, 1.0)
add_file("product-shot.png", "3.6 / 5.8 MB · Uploading", states.Uploading, 0.62)
add_file("archive.zip", "28 MB · Exceeds the 20 MB limit", states.Rejected, 0.0)
drop = fluentqt.FileDropZone(panel)
drop.setObjectName("fileDropZone")
drop.setDescription("Add documents, images or a ZIP archive.")
drop.setHintText("PDF, PNG, JPG, ZIP · Up to 20 MB per file")
layout.addWidget(drop)
heading = fluentqt.Label("Files", panel)
heading.setFluentTypography(fluentqt.FontRole.BodyStrong)
layout.addWidget(heading)
files = fluentqt.FileListView(panel)
files.setObjectName("selectedFiles")
files.setAccessibleName("Selected files")
files.setBackgroundVisible(False)
files.setBorderVisible(False)
files.setProperty("fluentPreserveParentSurface", True)
files.viewport().setProperty("fluentPreserveParentSurface", True)
files.setMinimumHeight(260)
files.setModel(model)
layout.addWidget(files)
files.removeRequested.connect(lambda index: model.removeRow(index.row()))
def accept_file(path):
file = QFileInfo(path)
if not file.isFile():
return
type_allowed = file.suffix().lower() in ("pdf", "png", "jpg", "jpeg", "zip")
size_allowed = file.size() <= 20 * 1024 * 1024
if not type_allowed or not size_allowed:
reason = "Choose a file under 20 MB."
if not type_allowed:
reason = "This file type is not supported."
drop.setErrorMessage(file.fileName() + " · " + reason)
add_file(file.fileName(), reason, states.Rejected, 0.0)
return
drop.clearError()
detail = f"{file.size() / (1024 * 1024):.1f} MB · Ready to use"
add_file(file.fileName(), detail, states.Ready, 1.0)
def dropped(urls):
for url in urls:
accept_file(url.toLocalFile())
def browse():
dialog = QFileDialog(panel, "Choose files")
dialog.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
dialog.setFileMode(QFileDialog.FileMode.ExistingFiles)
dialog.setNameFilter("Documents (*.pdf *.png *.jpg *.jpeg *.zip)")
dialog.filesSelected.connect(
lambda paths: [accept_file(path) for path in paths]
)
dialog.open()
panel._file_dialog = dialog
drop.filesDropped.connect(dropped)
drop.browseRequested.connect(browse)API
宣言を表示一致する API メンバーはありません。
fluent::basicinput::FileDropZone
継承元 QWidget · FluentElement · QMLPlus
アプリ提供のファイルピッカーを開くボタンを備えたローカルファイル用ドロップ領域です。ローカルファイルのみを受け付け(リモート URL を含むドラッグは無視します)、ファイルダイアログと入出力はアプリ側で処理します。
コンストラクタ
メソッド
QString hintText() const形式やサイズ上限を示すオプションのヒントテキスト。
void setHintText(const QString& text)形式やサイズ上限を示すオプションのヒントテキスト。
QString errorMessage() constクリアされるまで説明テキストを一時的に置き換える検証エラーテキストです。後続のドロップ操作では自動的にクリアされません。
void setErrorMessage(const QString& message)クリアされるまで説明テキストを一時的に置き換える検証エラーテキストです。後続のドロップ操作では自動的にクリアされません。
プロパティ
QString title- 読み取り
title()書き込みsetTitle()通知シグナルtitleChanged() QString description- 読み取り
description()書き込みsetDescription()通知シグナルdescriptionChanged() QString hintText形式やサイズ上限を示すオプションのヒントテキスト。
読み取りhintText()書き込みsetHintText()通知シグナルhintTextChanged()QString browseText- 読み取り
browseText()書き込みsetBrowseText()通知シグナルbrowseTextChanged() QString errorMessageクリアされるまで説明テキストを一時的に置き換える検証エラーテキストです。後続のドロップ操作では自動的にクリアされません。
読み取りerrorMessage()書き込みsetErrorMessage()通知シグナルerrorMessageChanged()bool dragActive- 読み取り
isDragActive()通知シグナルdragActiveChanged()
シグナル
void hintTextChanged(const QString& text)形式やサイズ上限を示すオプションのヒントテキスト。
void errorMessageChanged(const QString& message)クリアされるまで説明テキストを一時的に置き換える検証エラーテキストです。後続のドロップ操作では自動的にクリアされません。
void browseRequested()アプリケーションが提供するファイルピッカーを要求します。
void filesDropped(const QList<QUrl>& urls)ドロップされたローカルファイルの URL を元の順序のまま伴って送出されます。
protected メンバー
メソッド
fluent::FluentElement から継承
列挙型
enum Themeデザイントークン解決時に使用されるグローバルな視覚テーマ。
Light = 0Dark = 1HighContrast = 2
メソッド
static void setTheme(Theme theme)グローバルテーマを更新し、アクティブな FluentElement インスタンスに通知します。
static void setThemeDeferred(Theme theme)現在の操作をブロックせずに、可視要素を優先したバッチ処理でテーマの更新をスケジュールします。
static Theme currentTheme()現在有効なグローバルテーマを返します。
static bool themeUsesDarkAppearance(Theme theme)テーマがダークベースのクロームおよびマテリアルトークンを使用するかどうかを返します。
static void refreshTheme()デザイントークンの変更後に再描画するため、現在のテーマを再ブロードキャストします。
static int themeGeneration()テーマ変更ごとに加算される単調増加カウンターです。鮮度チェックに使用されます。
Theme effectiveTheme() const継承された QWidget の上書きを尊重し、この要素が使用するテーマを解決します。
bool effectiveThemeUsesDarkAppearance() constこの要素の有効なテーマがダークベースのクロームを使用するかどうかを返します。
bool setThemeOverrides(const QJsonObject& overrides)この要素のスパースな色、角丸半径、フォントトークンの上書きを置き換えます。
QJsonObject themeOverrides() constこの要素に設定されたオーバーライドを返します。
void clearThemeOverrides()すべてのトークンフィールドをグローバルテーマの既定値に復元します。
const Colors& themeColorsRef() const描画のホットパス向けにアクティブなカラーセットへ非コピーでアクセスします。
Material::AcrylicToken themeAcrylic() constマテリアル、エレベーション、およびアダプティブレイアウトのトークン。
QColor themeBackdrop(bool active) const指定されたアクティブ状態に対するウィンドウ chrome の背景色。
virtual void onThemeUpdated()グローバルテーマの変更後に呼び出されます。
型とエイリアス
struct Colorsコンポーネントに返されるデザイントークンのスナップショット。
fluent::QMLPlus から継承
メソッド
AnchorLayout::Anchors* anchors()QWidget ホストの変更可能なアンカーを返します。
void setState(const QString& name)登録済みの状態を名前で適用するか、@p name が空の場合はデフォルト状態を復元します。未知の名前は無視され、その状態を離れると既存のバインディングが再開されます。
void addState(const QMLState& state)名前付き状態定義を登録または置換します。アクティブな状態を置換した場合は即座に適用されます。
void evaluateStates()登録順に状態条件を再評価し、最初に一致した状態(一致しない場合はデフォルト状態)をアクティブにします。依存プロパティの変更通知時にも自動実行され、extend を使用する派生状態は、循環や欠損がない限り祖先の変更を継承します。
QMLPlusRuntime* runtime()このホストが所有し、遅延生成される状態オブザーバーを返します。
void setAnchors(const AnchorLayout::Anchors& anchors)すべてのホストアンカーを置き換え、親レイアウトを無効化します。
void resetAnchors()ホストのすべてのアンカーをクリアし、親レイアウトを無効化します。
void bind(const char* targetProp, QObject* source, const char* sourceProp, PropertyBinder::Direction dir = PropertyBinder::OneWay)PropertyBinder::bind() を介して、@p source の @p sourceProp をこの QWidget ホストの @p targetProp にバインドします。
BindingHandle bindManaged(const char* targetProp, QObject* source, const char* sourceProp, PropertyBinder::Direction direction = PropertyBinder::OneWay, BindingOptions options = {})この QWidget ホストに管理された直接バインディングを設定します。
BindingHandle bindComputed(const char* targetProp, const QVector<BindingDependency>& dependencies, std::function<QVariant()> evaluate, BindingOptions options = {})この QWidget ホストに明示的依存関係を持つ C++ 式を設定します。
void addTransition(const StateTransition& transition)優先順位順に状態遷移を登録します。
void setBehavior(const char* propertyName, const PropertyAnimation& animation)writeProperty() またはバインディング経由で @p propertyName が書き込まれた際に使用されるデフォルトアニメーションを設定します。明示的な StateTransition ルールが優先され、C++ のセッターを直接呼び出した場合はアニメーションしません。
void clearBehavior(const char* propertyName)今後のマネージド書き込みに使用するデフォルトアニメーションを削除します。
bool writeProperty(const char* propertyName, const QVariant& value)バインディングを削除せずに Behavior 経由でホストプロパティに書き込みます。
Qt 基底クラスドキュメント:QWidget