Fluent-Qt

基礎指南

字型與文字樣式

為標籤與自訂控制項套用預設的 Fluent 字級與字重。

預設字級規格

Typography 提供從 12px 說明文字到 68px 展示標題共 9 檔預設規格:Caption(12px)、Body(14px)、BodyStrong(14px 半粗體)、BodyLarge(18px)、BodyLargeStrong(18px 半粗體)、Subtitle(20px)、Title(28px)、TitleLarge(40px)與 Display(68px)。在 Label 上呼叫 setFluentTypography() 即可套用。

#include <FluentQt/TextFields.h>

auto* title = new fluent::textfields::Label("Account settings", this);
title->setFluentTypography(Typography::FontRole::Subtitle);

用於一般 QWidget

若要為一般 Qt 控制項設定字型,C++ 請使用 Typography::fontStyle(role).toQFont(),Python 請使用 fluentqt.font_for_role(role)。請注意,直接對 Fluent 控制項呼叫 QWidget::setFont 可能會讓它在切換主題時停止自動更新字型。

#include <FluentQt/Design.h>

customWidget->setFont(Typography::fontStyle(Typography::FontRole::BodyStrong).toQFont());

API 參考