文字輸入
LineEdit 單行輸入框
具備 Fluent 樣式與清除按鈕的單行文字方塊。
範例
屬性預覽載入失敗。請再次點選屬性預覽重試。

用法
單位與行內操作
使用 setTrailingText() 顯示單位、setTrailingWidget() 加入行內操作,並為輸入框與清除按鈕設定無障礙名稱。
#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 單行文字輸入框。包裝 QLineEdit 並提供 token 驅動的邊界、排版樣式、外框可見性與邊框寬度。
建構函式
解構函式
方法
QMargins contentMargins() const文字周圍的內容邊距(水平值包含 Qt 內部的文字內縮)。
void setContentMargins(const QMargins& margins)文字周圍的內容邊距(水平值包含 Qt 內部的文字內縮)。
Typography::FontRole fontRole() const文字使用的 Fluent Typography 預設樣式。
void setFontRole(Typography::FontRole role)文字使用的 Fluent Typography 預設樣式。
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)使用 WidgetOwnership 設定自訂尾端控制項與其清理方式(不接受自身或上層控制項);切換所有權模式前需先呼叫 takeTrailingWidget()。
QWidget* takeTrailingWidget()移除並回傳尾端控制項,交由呼叫端管理或刪除。
void releaseTrailingWidget()移除尾端控制項,並依其 WidgetOwnership 模式進行清理。
屬性
QMargins contentMargins文字周圍的內容邊距(水平值包含 Qt 內部的文字內縮)。
讀取contentMargins()設定setContentMargins()變更訊號contentMarginsChanged()Typography::FontRole fontRole文字使用的 Fluent Typography 預設樣式。
讀取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()
訊號
void contentMarginsChanged()文字周圍的內容邊距(水平值包含 Qt 內部的文字內縮)。
void fontRoleChanged()文字使用的 Fluent Typography 預設樣式。
void clearButtonEnabledChanged()尾端清除按鈕是否啟用。
void clearButtonSizeChanged()清除按鈕的尺寸,預設為 24 個邏輯像素。
void clearButtonOffsetChanged()套用於清除按鈕的像素位移。
void focusedBorderWidthChanged()取得焦點時的底部邊框寬度。
void unfocusedBorderWidthChanged()未取得焦點時的底部邊框寬度;預設為零(無底線)。
void frameVisibleChanged()LineEdit 是否繪製輸入框外框與焦點底線。
受保護成員
方法
virtual void paintFrame(QPainter& painter)在啟用 frameVisible 時繪製輸入框背景與邊框。
繼承自 fluent::FluentElement
列舉
enum Theme解析設計 token 時使用的全域視覺佈景主題。
Light = 0Dark = 1HighContrast = 2
方法
static void setTheme(Theme theme)更新全域主題,並通知使用中的 FluentElement 執行個體。
static void setThemeDeferred(Theme theme)排程以可見元素優先的批次主題重新整理,避免阻斷目前的互動。
static Theme currentTheme()傳回目前生效的全域主題。
static bool themeUsesDarkAppearance(Theme theme)傳回主題是否使用深色底的視窗框架與材質 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()在全域主題變更後呼叫。
型別與別名
struct Colors傳回給元件使用的設計 token 快照。
繼承自 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 setBehavior(const char* propertyName, const PropertyAnimation& animation)設定透過 writeProperty() 或繫結寫入 @p propertyName 時使用的預設動畫。明確的 StateTransition 規則優先;直接呼叫 C++ setter 不會有動畫。
void clearBehavior(const char* propertyName)移除後續受管理寫入所使用的預設動畫。
bool writeProperty(const char* propertyName, const QVariant& value)透過 Behavior 寫入宿主屬性,且不移除該屬性的繫結。
Qt 基底類別文件:QLineEdit