Fluent-Qt

文本输入

CodeBlock 代码块

只读显示代码,带语法高亮和复制按钮。

示例

代码块的真实 Gallery 示例

用法

阅读和复制代码

setLanguage() 设置语言,setCode() 设置代码;标题栏可以复制全部代码或折叠代码块。

#include <FluentQt/TextFields.h>
using namespace fluent::textfields;

auto* code = new CodeBlock(this);
code->setLanguage("cpp");
code->setCode("// A small FluentQt window\n"
              "auto* button = new Button(\"Continue\");\n"
              "button->setFluentStyle(Button::Accent);");

fluent::textfields::CodeBlock

继承自 layout::Expander

支持语法配色、精确复制、折叠和限高滚动的只读代码块。

构造函数

属性

QString code
读取 code()设置 setCode()通知 codeChanged()
QString language
读取 language()设置 setLanguage()通知 languageChanged()
bool wordWrap
读取 isWordWrapEnabled()设置 setWordWrap()通知 wordWrapChanged()
int maxVisibleLines

最大可见行数,0 表示完整展开所有内容,默认 16。

读取 maxVisibleLines()设置 setMaxVisibleLines()通知 maxVisibleLinesChanged()

方法

int maxVisibleLines() const

最大可见行数,0 表示完整展开所有内容,默认 16。

void setMaxVisibleLines(int lines)

最大可见行数,0 表示完整展开所有内容,默认 16。

void copy()

复制原始代码,并在宿主剪贴板操作完成后报告结果。

信号

void maxVisibleLinesChanged(int lines)

最大可见行数,0 表示完整展开所有内容,默认 16。

继承自 fluent::layout::Expander

属性

QString headerText
读取 headerText()设置 setHeaderText()通知 headerTextChanged()
QWidget* contentWidget
读取 contentWidget()设置 setContentWidget()通知 contentWidgetChanged()
bool expanded
读取 isExpanded()设置 setExpanded()通知 expandedChanged()
bool animationEnabled
读取 isAnimationEnabled()设置 setAnimationEnabled()通知 animationEnabledChanged()

方法

信号

继承自 fluent::layout::Card

属性

Appearance appearance
读取 appearance()设置 setAppearance()通知 appearanceChanged()
bool borderVisible
读取 isBorderVisible()设置 setBorderVisible()通知 borderVisibleChanged()

方法

信号

枚举

enum Appearance

Card 填充所使用的 token 表面。

  • Layer
  • LayerAlt
  • Canvas
继承自 fluent::FluentElement

方法

static void setTheme(Theme theme)

更新全局主题,并通知所有活跃的 FluentElement 实例。

static void setThemeDeferred(Theme theme)

以可见元素优先的批次调度主题刷新,避免阻塞当前交互。

static Theme currentTheme()

返回当前生效的全局主题。

static bool themeUsesDarkAppearance(Theme theme)

返回指定主题是否使用暗色底的 chrome 与材质 token。

static void refreshTheme()

在设计 token 变化后重新广播当前主题以触发重绘。

static int themeGeneration()

每次主题变化自增的单调计数器,用于过期判断。

Theme effectiveTheme() const

解析此元素实际使用的主题,会优先读取 QWidget 父链上的局部主题覆盖。

bool effectiveThemeUsesDarkAppearance() const

返回此元素的实际主题是否使用暗色底 chrome。

bool setThemeOverrides(const QJsonObject& overrides)

供组件侧访问的设计 token 接口。

QJsonObject themeOverrides() const

返回当前元素的覆盖配置。

void clearThemeOverrides()

恢复全部 token 跟随全局主题。

const Colors& themeColorsRef() const

对当前色板的零拷贝访问(用于绘制热路径)。

Material::AcrylicToken themeAcrylic() const

材质、阴影和自适应布局 token。

QColor themeBackdrop(bool active) const

给定激活状态下的窗口 chrome 背景色。

virtual void onThemeUpdated()

全局主题变化后调用。

枚举

enum Theme

解析设计 token 时使用的全局视觉主题。

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

类型与别名

struct Colors

返回给组件使用的设计 token 快照。

继承自 fluent::QMLPlus

方法

AnchorLayout::Anchors* anchors()

返回 QWidget 宿主的可变锚点配置。

void setState(const QString& name)

应用具名 state;名称为空时恢复默认状态。

void addState(const QMLState& state)

注册或替换一个具名 state 定义。

void evaluateStates()

重新计算条件;按注册顺序选择首个成立的条件。

QMLPlusRuntime* runtime()

返回按需创建、由宿主持有的状态观察对象。

void setAnchors(const AnchorLayout::Anchors& anchors)

替换宿主的全部锚点,并使父布局失效。

void resetAnchors()

清除宿主全部锚点,并使父布局失效。

void addTransition(const StateTransition& transition)

按优先顺序注册状态过渡。

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

设置宿主受管理属性写入时使用的默认动画。

void clearBehavior(const char* propertyName)

移除后续受管理写入使用的默认动画。

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

通过 Behavior 写入宿主属性,且不移除该属性的绑定。

Qt 基类完整成员:QFrame