基礎指南
主題與顏色
切換淺色、深色或高對比主題,並在自訂繪製程式碼中讀取主題配色。
切換全域主題
呼叫 FluentElement::setTheme() 可在 Light、Dark 與 HighContrast 之間切換並自動重繪所有控制項。若只想修改單一控制項的配色或尺寸,請傳入 JSON 物件給 setThemeOverrides(),這些覆寫在切換主題時仍會保留。
#include <FluentQt/Foundation.h>
fluent::FluentElement::setTheme(fluent::FluentElement::Dark);import fluentqt
fluentqt.set_theme(fluentqt.Theme.Dark)讀取主題顏色
請使用 bgCanvas 或 textPrimary 等具名色彩取代寫死的 RGB 數值,讓自訂繪製隨主題自動更新。在 C++ 中呼叫 themeColorsRef();在 Python 中繼承 fluentqt.FluentWidget 並呼叫 theme_tokens()。
#include <FluentQt/Foundation.h>
// Inside a FluentElement-based widget's paintEvent()
const auto& colors = themeColorsRef();
const QColor background = colors.bgCanvas;
const QColor text = colors.textPrimary;import fluentqt
class Swatch(fluentqt.FluentWidget):
def paintEvent(self, event):
colors = self.theme_tokens().colors
background = colors.bgCanvas
text = colors.textPrimary