基础输入
RadioButton 单选按钮
在一组选项中只能选择一项。
示例

用法
单选按钮组
同一父控件下的 RadioButton 自动互斥;在 toggled(true) 时读取选中的选项。
#include <FluentQt/BasicInput.h>
using namespace fluent::basicinput;
#include <FluentQt/TextFields.h>
auto* low = new RadioButton("Low", this);
auto* medium = new RadioButton("Medium", this);
auto* high = new RadioButton("High", this);
medium->setChecked(true);
auto* status = new fluent::textfields::Label("Selected: Medium", this);
status->setFluentTypography(Typography::FontRole::Body);
status->setTextColorRole(fluent::textfields::Label::TextColorRole::Primary);
status->setMinimumWidth(status->sizeHint().width());
for (auto* radio : {low, medium, high}) {
connect(radio, &RadioButton::toggled, status, [radio, status](bool checked) {
if (checked)
status->setText(QString("Selected: %1").arg(radio->text()));
});
}import fluentqt
status = fluentqt.Label('Selected: Medium')
status.setFluentTypography(fluentqt.FontRole.Body)
status.setTextColorRole(fluentqt.Label.TextColorRole.Primary)
status.setMinimumWidth(status.sizeHint().width())
low = fluentqt.RadioButton('Low')
medium = fluentqt.RadioButton('Medium')
high = fluentqt.RadioButton('High')
medium.setChecked(True)
for radio in (low, medium, high):
radio.toggled.connect(
lambda checked, value=radio: status.setText(
f"Selected: {value.text()}"
) if checked else None
)API
查看声明没有匹配的 API 成员。
fluent::basicinput::RadioButton
继承自 QRadioButton · FluentElement · QMLPlus
带选中动画反馈的 Fluent 单选按钮。
构造函数
属性
qreal checkProgress归一化的选中态动画进度。
读取checkProgress()设置setCheckProgress()qreal dotScale单选按钮选中圆点的动画缩放值。
读取dotScale()设置setDotScale()int circleSize单选按钮外圈直径,单位为像素。
读取circleSize()设置setCircleSize()通知circleSizeChanged()int textGap控件图形与文本内容之间的间距。
读取textGap()设置setTextGap()通知textGapChanged()QFont textFont单选按钮文本使用的字体。
读取textFont()设置setTextFont()通知textFontChanged()
方法
qreal checkProgress() const归一化的选中态动画进度。
void setCheckProgress(qreal progress)归一化的选中态动画进度。
qreal dotScale() const单选按钮选中圆点的动画缩放值。
void setDotScale(qreal scale)单选按钮选中圆点的动画缩放值。
int circleSize() const单选按钮外圈直径,单位为像素。
void setCircleSize(int size)单选按钮外圈直径,单位为像素。
int textGap() const控件图形与文本内容之间的间距。
void setTextGap(int gap)控件图形与文本内容之间的间距。
QFont textFont() const单选按钮文本使用的字体。
void setTextFont(const QFont& font)单选按钮文本使用的字体。
信号
void circleSizeChanged()单选按钮外圈直径,单位为像素。
void textGapChanged()控件图形与文本内容之间的间距。
void textFontChanged()单选按钮文本使用的字体。
子类扩展接口
方法
继承自 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 基类完整成员:QRadioButton