文本输入
LineEdit 单行输入框
输入单行文字。
示例

用法
带清除按钮
setClearButtonEnabled(true) 在有文字时显示清除按钮,textChanged 给出当前文字。
#include <FluentQt/TextFields.h>
using namespace fluent::textfields;
auto* width = new LineEdit(this);
width->setAccessibleName("Canvas width");
width->setText("1280");
width->setTrailingText("px");
width->setClearButtonAccessibleName("Clear canvas width");
width->setClearButtonFocusPolicy(Qt::StrongFocus);
auto* name = new LineEdit(this);
name->setAccessibleName("Export name");
name->setText("gallery-preview-v2");
name->setClearButtonEnabled(false);
auto* reset = new Button("Reset");
reset->setFluentStyle(Button::Subtle);
reset->setFluentSize(Button::Small);
reset->setFontRole(Typography::FontRole::Caption);
auto actionFont = reset->font();
actionFont.setStyleName(QString());
actionFont.setWeight(QFont::DemiBold);
reset->setFont(actionFont);
reset->setTextColorRole(Button::TextColorRole::Accent);
reset->setFixedSize(Spacing::XXLarge, Spacing::ControlHeight::Small);
reset->setFocusVisual(true);
reset->setAccessibleName("Reset export name");
name->setTrailingWidget(reset, WidgetOwnership::Owned);
connect(reset, &Button::clicked, name, [name] {
name->setText("gallery-preview");
});import fluentqt
from PySide6.QtCore import Qt
from PySide6.QtGui import QFont
width_column = root.add_column()
name_column = root.add_column()
width = fluentqt.LineEdit(width_column)
width.setAccessibleName('Canvas width')
width.setText('1280')
width.setTrailingText('px')
width.setClearButtonAccessibleName('Clear canvas width')
width.setClearButtonFocusPolicy(Qt.StrongFocus)
name = fluentqt.LineEdit(name_column)
name.setAccessibleName('Export name')
name.setText('gallery-preview-v2')
name.setClearButtonEnabled(False)
reset = fluentqt.Button('Reset')
reset.setFluentStyle(fluentqt.Button.ButtonStyle.Subtle)
reset.setFluentSize(fluentqt.Button.ButtonSize.Small)
reset.setFontRole(fluentqt.FontRole.Caption)
action_font = reset.font()
action_font.setStyleName('')
action_font.setWeight(QFont.DemiBold)
reset.setFont(action_font)
reset.setTextColorRole(fluentqt.Button.TextColorRole.Accent)
reset.setFixedSize(fluentqt.Spacing.XXLarge, fluentqt.Spacing.ControlHeight.Small)
reset.setFocusVisual(True)
reset.setAccessibleName('Reset export name')
name.setTrailingWidget(reset, fluentqt.WidgetOwnership.Owned)
reset.clicked.connect(lambda: name.setText('gallery-preview'))API
查看声明没有匹配的 API 成员。
fluent::textfields::LineEdit
继承自 QLineEdit · FluentElement · QMLPlus
带清除按钮和焦点下划线的 Fluent 单行文本输入框。
构造函数
属性
QMargins contentMargins内容边距;水平值已包含 Qt 内部文字留白,零值不会重复增加原生边距。
读取contentMargins()设置setContentMargins()通知contentMarginsChanged()Typography::FontRole fontRole文本绘制使用的 Fluent 排版角色。
读取fontRole()设置setFontRole()通知fontRoleChanged()bool clearButtonEnabled尾部清除按钮是否启用。
读取isClearButtonEnabled()设置setClearButtonEnabled()通知clearButtonEnabledChanged()int clearButtonSize清除按钮尺寸,默认为 24 个逻辑像素。
读取clearButtonSize()设置setClearButtonSize()通知clearButtonSizeChanged()QPoint clearButtonOffset清除按钮应用的像素偏移。
读取clearButtonOffset()设置setClearButtonOffset()通知clearButtonOffsetChanged()int focusedBorderWidth聚焦时底部边框宽度。
读取focusedBorderWidth()设置setFocusedBorderWidth()通知focusedBorderWidthChanged()int unfocusedBorderWidth未聚焦时底部边框宽度。
读取unfocusedBorderWidth()设置setUnfocusedBorderWidth()通知unfocusedBorderWidthChanged()bool frameVisibleLineEdit 是否绘制输入框外框和焦点下划线。
读取isFrameVisible()设置setFrameVisible()通知frameVisibleChanged()QString trailingText- 读取
trailingText()设置setTrailingText()通知trailingTextChanged() QWidget* trailingWidget- 读取
trailingWidget()通知trailingWidgetChanged() fluent::WidgetOwnership trailingWidgetOwnership- 读取
trailingWidgetOwnership()通知trailingWidgetOwnershipChanged() QString clearButtonAccessibleName- 读取
clearButtonAccessibleName()设置setClearButtonAccessibleName()通知clearButtonAccessibleNameChanged() Qt::FocusPolicy clearButtonFocusPolicy- 读取
clearButtonFocusPolicy()设置setClearButtonFocusPolicy()通知clearButtonFocusPolicyChanged()
方法
QMargins contentMargins() const内容边距;水平值已包含 Qt 内部文字留白,零值不会重复增加原生边距。
void setContentMargins(const QMargins& margins)内容边距;水平值已包含 Qt 内部文字留白,零值不会重复增加原生边距。
Typography::FontRole fontRole() const文本绘制使用的 Fluent 排版角色。
void setFontRole(Typography::FontRole role)文本绘制使用的 Fluent 排版角色。
bool isClearButtonEnabled() const尾部清除按钮是否启用。
void setClearButtonEnabled(bool enabled)尾部清除按钮是否启用。
int clearButtonSize() const清除按钮尺寸,默认为 24 个逻辑像素。
void setClearButtonSize(int size)清除按钮尺寸,默认为 24 个逻辑像素。
QPoint clearButtonOffset() const清除按钮应用的像素偏移。
void setClearButtonOffset(const QPoint& offset)清除按钮应用的像素偏移。
int focusedBorderWidth() const聚焦时底部边框宽度。
void setFocusedBorderWidth(int width)聚焦时底部边框宽度。
int unfocusedBorderWidth() const未聚焦时底部边框宽度。
void setUnfocusedBorderWidth(int width)未聚焦时底部边框宽度。
bool isFrameVisible() constLineEdit 是否绘制输入框外框和焦点下划线。
void setFrameVisible(bool visible)LineEdit 是否绘制输入框外框和焦点下划线。
void setTrailingText(const QString& text)显示纯文字尾缀,不改变可编辑值,并替换已承载的控件内容。
bool setTrailingWidget(QWidget* widget, WidgetOwnership ownership)按显式所有权承载一个尾部控件;拒绝宿主自身及祖先控件。
QWidget* takeTrailingWidget()脱离并将自定义尾部控件交回调用方。
void releaseTrailingWidget()按记录的所有权策略释放自定义尾部内容。
信号
void contentMarginsChanged()内容边距;水平值已包含 Qt 内部文字留白,零值不会重复增加原生边距。
void fontRoleChanged()文本绘制使用的 Fluent 排版角色。
void clearButtonEnabledChanged()尾部清除按钮是否启用。
void clearButtonSizeChanged()清除按钮尺寸,默认为 24 个逻辑像素。
void clearButtonOffsetChanged()清除按钮应用的像素偏移。
void focusedBorderWidthChanged()聚焦时底部边框宽度。
void unfocusedBorderWidthChanged()未聚焦时底部边框宽度。
void frameVisibleChanged()LineEdit 是否绘制输入框外框和焦点下划线。
析构函数
子类扩展接口
方法
virtual void paintFrame(QPainter& painter)frameVisible 启用时绘制输入表面,派生输入框可复用同一开关。
继承自 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 = 0Dark = 1HighContrast = 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 bind(const char* targetProp, QObject* source, const char* sourceProp, PropertyBinder::Direction dir = PropertyBinder::OneWay)将 source 属性绑定到 QWidget 宿主上的 target 属性。
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 setBehavior(const char* propertyName, const PropertyAnimation& animation)设置宿主受管理属性写入时使用的默认动画。
void clearBehavior(const char* propertyName)移除后续受管理写入使用的默认动画。
bool writeProperty(const char* propertyName, const QVariant& value)通过 Behavior 写入宿主属性,且不移除该属性的绑定。
Qt 基类完整成员:QLineEdit