Fluent-Qt

Basic input

FileDropZone

A file entry surface with drag feedback, keyboard access, and a separate browse action.

Example

FileDropZone: Add to your workspace

Usage

Add to your workspace

Use setDescription() and setHintText() to describe accepted files. The example lists chosen files in a FileListView below.

#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);
});

fluent::basicinput::FileDropZone

Inherits QWidget · FluentElement · QMLPlus

File entry surface with local-URL drop and application-owned browsing.

Constructors

Properties

QString title
Read title()Write setTitle()Notify titleChanged()
QString description
Read description()Write setDescription()Notify descriptionChanged()
QString hintText

Optional application-owned limits or format hint.

Read hintText()Write setHintText()Notify hintTextChanged()
QString browseText
Read browseText()Write setBrowseText()Notify browseTextChanged()
QString errorMessage

Validation feedback that replaces the description until cleared.

Read errorMessage()Write setErrorMessage()Notify errorMessageChanged()
bool dragActive
Read isDragActive()Notify dragActiveChanged()

Methods

QString hintText() const

Optional application-owned limits or format hint.

void setHintText(const QString& text)

Optional application-owned limits or format hint.

QString errorMessage() const

Validation feedback that replaces the description until cleared.

void setErrorMessage(const QString& message)

Validation feedback that replaces the description until cleared.

Signals

void hintTextChanged(const QString& text)

Optional application-owned limits or format hint.

void errorMessageChanged(const QString& message)

Validation feedback that replaces the description until cleared.

void browseRequested()

Requests an application-provided file picker.

void filesDropped(const QList<QUrl>& urls)

Delivers local URLs in their original order after an accepted copy drop.

Subclass interfaces

Methods

Inherited from fluent::FluentElement

Methods

static void setTheme(Theme theme)

Updates the global theme and notifies active FluentElement instances.

static void setThemeDeferred(Theme theme)

Schedules a visible-first batched theme refresh without blocking the current interaction.

static Theme currentTheme()

Returns the currently active global theme.

static bool themeUsesDarkAppearance(Theme theme)

Returns whether a theme uses dark-backed chrome and material tokens.

static void refreshTheme()

Re-broadcasts the current theme to repaint after a design-token change.

static int themeGeneration()

Monotonic counter bumped on every theme change, for staleness checks.

Theme effectiveTheme() const

Resolves the theme used by this element, honoring an inherited QWidget override.

bool effectiveThemeUsesDarkAppearance() const

Returns whether this element's effective theme uses dark-backed chrome.

QJsonObject themeOverrides() const

Returns this element's authored overrides.

void clearThemeOverrides()

Restores all token fields to global theme defaults.

const Colors& themeColorsRef() const

Non-copying access to the active color set (for hot paint paths).

Material::AcrylicToken themeAcrylic() const

Material, elevation, and adaptive layout tokens.

QColor themeBackdrop(bool active) const

Window-chrome backdrop color for the given activation state.

virtual void onThemeUpdated()

Called after the global theme changes.

Enumerations

enum Theme

Global visual theme used when resolving design tokens.

  • Light = 0
  • Dark = 1
  • HighContrast = 2

Types and aliases

struct Colors

Design token snapshots returned to components.

Inherited from fluent::QMLPlus

Methods

AnchorLayout::Anchors* anchors()

Returns mutable anchors for the QWidget host.

void setState(const QString& name)

Applies a named state, or clears state when name is empty.

void addState(const QMLState& state)

Registers or replaces a named state definition.

void evaluateStates()

Reevaluates conditions; the first registered true condition wins.

QMLPlusRuntime* runtime()

Returns the lazy host-owned state observation object.

void setAnchors(const AnchorLayout::Anchors& anchors)

Replaces all host anchors and invalidates the parent layout.

void resetAnchors()

Clears all host anchors and invalidates the parent layout.

void addTransition(const StateTransition& transition)

Registers a state transition in precedence order.

void setBehavior(const char* propertyName, const PropertyAnimation& animation)

Sets the default animation for this host's managed property writes.

void clearBehavior(const char* propertyName)

Removes the default animation for future managed writes.

bool writeProperty(const char* propertyName, const QVariant& value)

Writes a host property through Behavior without removing its binding.

All inherited Qt members:QWidget