QML FluentUI
repository·main·Indexed 26 days ago
https://github.com/zhuzichu520/fluentuiA component library for Qt QML that implements Microsoft's Fluent Design system. It provides a comprehensive set of UI components including application shells (FluApp, FluWindow), input controls (FluButton, FluTextBox), data display elements (FluProgressBar, FluTreeView), and navigation components. The library supports Qt 6 (main branch) and Qt 5, offering specialized tools like FluTreeModel for hierarchical data and FluHotkey for global keyboard shortcuts.
What's inside fluentui
- The FluentUI library for QML provides a comprehensive set of components designed to build modern, Fluent-style user interfaces. The component catalog includes application shells, input controls, navigation elements, and data display components.
Internationalization Best Practices in FluentUI
mainTo avoid compilation failures and character encoding issues (mojibake), follow these rules for text and internationalization:
- File Encoding: Use
UTF-8without BOM. - Avoid Hardcoded Chinese: Do not include Chinese characters directly in the code or comments, as this can change file formats and cause build errors.
- Use Internationalization Functions: Always use the provided translation functions instead of hardcoded strings:
- In C++: Use the
tr()function. - In QML: Use the
qsTr()function.
- In C++: Use the
- File Encoding: Use
Build QML FluentUI from source
mainTo build the library from source, clone the repository recursively and use CMake with the Ninja generator. You must provide the path to your Qt SDK via
-DCMAKE_PREFIX_PATH.Note: The main branch supports Qt 6. For Qt 5 support, switch to the Qt 5 branch.
git clone --recursive https://github.com/zhuzichu520/FluentUI.git cd FluentUI mkdir build cd build cmake -DCMAKE_PREFIX_PATH=<YOUR_QT_SDK_DIR_PATH> -DCMAKE_BUILD_TYPE=Release -GNinja <仓库路径> cmake --build . --config Release --target all --parallelDeploy Releases for Windows and macOS
mainThe
Script-DeployReleasescript automates the deployment process by executing Qt's deployment tools.Note: This script is only supported on Windows and macOS. It is not supported on Linux.
Prerequisites for QML FluentUI
mainBefore using the QML FluentUI library, ensure your environment meets the following requirements:
Required Modules:
- Qt Core
- Qt Quick
- Qt QML
- Qt ShaderTool
- Qt 5 Compatibility Module (Important)
Optional Modules:
- Qt LinguistTool (for translations)
- Qt Svg (Required if using Qt 5)
It is recommended to use the Qt Online Installer to obtain these modules.
Update Translations (ts and qm files)
mainUse the
Script-UpdateTranslationsscript to manage your translation workflow. This is required whenever you add newtr()(C++) orqsTr()(QML) calls to your code.Workflow:
- Add
tr()orqsTr()functions to your source code. - Run
Script-UpdateTranslationsto update the.tsfiles. - Write your translations in the
.tsfiles. - Run
Script-UpdateTranslationsagain to update the.qmfiles, making the translations effective in the application.
- Add
Update translations using Script-UpdateTranslations
mainUse the
Script-UpdateTranslationsscript to manage translation files (.tsand.qm) after adding new translatable strings viatr()orqsTr():- Run the script to update the
.tsfiles based on your code changes. - Write the necessary translations in the
.tsfiles. - Run the script again to update the
.qmfiles, making the translations effective in the application.
- Run the script to update the
Configure development environment for FluentUI scaffolding
mainWhen developing with the FluentUI scaffolding, ensure the following environment settings are met to avoid compilation failures:
- macOS Permissions: Grant full permissions to the entire project path to prevent compilation errors caused by missing permissions.
- File Encoding: Use
UTF-8without BOM. Avoid using Chinese characters (including comments) directly in the code, as they may change the file format or cause garbled text during compilation. - Internationalization (i18n): Instead of hardcoding Chinese characters, use the provided internationalization functions:
- In C++: Use the
tr()function. - In QML: Use the
qsTr()function.
- In C++: Use the
Deploy releases using Script-DeployRelease
mainThe
Script-DeployReleasescript automates the deployment process by executing Qt's deployment tools.- Supported Platforms: Windows and macOS.
- Functionality: Executes
windeployqton Windows ormacdeployqton macOS. - Note: This script is not supported on Linux.
Overview of supported FluentUI components
mainQML FluentUI provides a variety of components designed to follow Fluent Design principles. Key components include:
- FluApp: Application entry point with SPA (Single Page Application) routing support.
- FluWindow: Frameless window (Windows only).
- FluAppBar: Title bar for windows supporting dragging, minimizing, maximizing, and closing.
- FluText: General text component.
- FluButton / FluFilledButton / FluTextButton: Various button styles.
- FluToggleButton: Toggleable button.
- FluIcon: General icon component.
- FluRadioButton: Radio button.
- FluTextBox / FluMultiLineTextBox: Single-line and multi-line input fields.
- FluToggleSwitch: Switch component.
Navigation and Specialized components
mainUse these components for advanced UI patterns:
FluMenu: A popup menu component.FluCarousel: A carousel for cycling through content.FluScrollbar: A scroll bar component.FluMediaPlayer: Multimedia playback components.FluFlipView: A flip view component for content transitions.FluTheme: Manages theme settings, including theme color changes and dark mode support.
Application Shell and Windowing components
mainUse these components to define the main structure and windowing behavior of your application:
FluApp: The initial entry point of the program. Supports Single Page Application (SPA) routing.FluWindow: A frameless window component (Note: This component only works on Windows).FluAppBar: A title bar component for the top of the window. Supports dragging, minimizing, maximizing, and closing.FluNavigationView: A responsive navigation view for application structure.