Skip to main content

cxx_qt_lib/quickcontrols/
qquickstyle.rs

1// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
2// SPDX-FileContributor: Joshua Goins <joshua.goins@kdab.com>
3//
4// SPDX-License-Identifier: MIT OR Apache-2.0
5
6#[cxx_qt::bridge]
7mod ffi {
8    unsafe extern "C++" {
9        include!("cxx-qt-lib/qquickstyle.h");
10        /// The `QQuickStyle` class allows configuring the application style.
11        ///
12        /// Qt Documentation: [QQuickStyle](https://doc.qt.io/qt/qquickstyle.html#details)
13        type QQuickStyle;
14
15        include!("cxx-qt-lib/qstring.h");
16        type QString = crate::QString;
17    }
18
19    #[namespace = "rust::cxxqtlib1"]
20    unsafe extern "C++" {
21        #[doc(hidden)]
22        #[rust_name = "qquickstyle_name"]
23        fn qquickstyleName() -> QString;
24
25        #[doc(hidden)]
26        #[rust_name = "qquickstyle_set_fallback_style"]
27        fn qquickstyleSetFallbackStyle(style: &QString);
28
29        #[doc(hidden)]
30        #[rust_name = "qquickstyle_set_style"]
31        fn qquickstyleSetStyle(style: &QString);
32    }
33}
34
35use crate::QString;
36pub use ffi::QQuickStyle;
37
38impl QQuickStyle {
39    /// Returns the name of the application style.
40    ///
41    /// **Note:** The application style can be specified by passing a `-style` command line argument. Therefore this function may not return a fully resolved value if called before constructing a [`QGuiApplication`](crate::QGuiApplication).
42    pub fn name() -> QString {
43        ffi::qquickstyle_name()
44    }
45
46    /// Sets the application fallback style to `style`.
47    ///
48    /// **Note:** The fallback style must be the name of one of the built-in Qt Quick Controls styles, e.g. "Material".
49    ///
50    /// **Note:** The style must be configured before loading QML that imports Qt Quick Controls. It is not possible to change the style after the QML types have been registered.
51    ///
52    /// The fallback style can be also specified by setting the `QT_QUICK_CONTROLS_FALLBACK_STYLE` [environment variable](https://doc.qt.io/qt/qtquickcontrols-environment.html).
53    pub fn set_fallback_style(style: &QString) {
54        ffi::qquickstyle_set_fallback_style(style)
55    }
56
57    /// Sets the application style to `style`.
58    ///
59    /// Note: The style must be configured before loading QML that imports Qt Quick Controls. It is not possible to change the style after the QML types have been registered.
60    pub fn set_style(style: &QString) {
61        ffi::qquickstyle_set_style(style)
62    }
63}