Fluent-Qt

日期与时间

CalendarView 日历视图

按月浏览并选择日期。

示例

日历视图的真实 Gallery 示例

用法

浏览和选择日期

setSelectedDate() 设置选中日期;点击标题可切换到月份和年份视图。

#include <FluentQt/DateTime.h>
using namespace fluent::date_time;

auto* calendar = new CalendarView(this);
calendar->setSelectedDate(QDate::currentDate());

fluent::date_time::CalendarView

继承自 QWidget · FluentElement · QMLPlus

用于按日、月、年层级浏览和选择日期的 Fluent 日历视图。

构造函数

属性

QDate selectedDate

选中日期;无效日期表示未选择。

读取 selectedDate()设置 setSelectedDate()通知 selectedDateChanged()
QDate visibleMonth

CalendarView 当前显示的月份。

读取 visibleMonth()设置 setVisibleMonth()通知 visibleMonthChanged()
QDate minDate

日历表面接受的最小日期。

读取 minDate()设置 setMinDate()通知 minDateChanged()
QDate maxDate

日历表面接受的最大日期。

读取 maxDate()设置 setMaxDate()通知 maxDateChanged()
QLocale locale

用于日历名称和自动每周起始日的区域设置。

读取 locale()设置 setLocale()通知 localeChanged()
Qt::DayOfWeek firstDayOfWeek

日历周布局使用的一周起始日。

读取 firstDayOfWeek()设置 setFirstDayOfWeek()重置 resetFirstDayOfWeek()通知 firstDayOfWeekChanged()
CalendarContentLevel contentLevel

当前显示的日历内容层级。

读取 contentLevel()设置 setContentLevel()通知 contentLevelChanged()
bool frameVisible

CalendarView 是否绘制自身外框。

读取 isFrameVisible()设置 setFrameVisible()通知 frameVisibleChanged()

方法

QDate selectedDate() const

选中日期;无效日期表示未选择。

QDate visibleMonth() const

CalendarView 当前显示的月份。

QDate minDate() const

日历表面接受的最小日期。

QDate maxDate() const

日历表面接受的最大日期。

QLocale locale() const

用于日历名称和自动每周起始日的区域设置。

Qt::DayOfWeek firstDayOfWeek() const

日历周布局使用的一周起始日。

CalendarContentLevel contentLevel() const

当前显示的日历内容层级。

bool isFrameVisible() const

CalendarView 是否绘制自身外框。

void setSelectedDate(const QDate& date)

选中日期;无效日期表示未选择。

void setVisibleMonth(const QDate& month)

CalendarView 当前显示的月份。

void setMinDate(const QDate& date)

日历表面接受的最小日期。

void setMaxDate(const QDate& date)

日历表面接受的最大日期。

void setLocale(const QLocale& locale)

用于日历名称和自动每周起始日的区域设置。

void setFirstDayOfWeek(Qt::DayOfWeek day)

日历周布局使用的一周起始日。

void resetFirstDayOfWeek()

日历周布局使用的一周起始日。

void setContentLevel(CalendarContentLevel level)

当前显示的日历内容层级。

void setFrameVisible(bool visible)

CalendarView 是否绘制自身外框。

信号

void selectedDateChanged(const QDate& date)

选中日期;无效日期表示未选择。

void visibleMonthChanged(const QDate& month)

CalendarView 当前显示的月份。

void minDateChanged(const QDate& date)

日历表面接受的最小日期。

void maxDateChanged(const QDate& date)

日历表面接受的最大日期。

void localeChanged(const QLocale& locale)

用于日历名称和自动每周起始日的区域设置。

void firstDayOfWeekChanged(Qt::DayOfWeek day)

日历周布局使用的一周起始日。

void contentLevelChanged(CalendarContentLevel level)

当前显示的日历内容层级。

void frameVisibleChanged(bool visible)

CalendarView 是否绘制自身外框。

枚举

析构函数

子类扩展接口

方法

继承自 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 基类完整成员:QWidget