在 qml Qt 中设置样式 [英] Setting the Style in qml Qt
问题描述
我想在 qml 中为我的元素设置样式.为此,我想使用像 Material Style 这样的样式.使用可以在以下位置找到的示例:
指出:
<块引用>要运行具有 Material 样式的应用程序,请参阅
- 或在 main.cpp 中添加
qputenv("QT_QUICK_CONTROLS_STYLE", "material");
.
- 或在 main.cpp 中添加
配置文件:
必须创建 qtquickcontrols2.conf 文件:
[控制]样式=材料
并且必须在 qresource 中:
<qresource prefix="/"><file>main.qml</file><file>qtquickcontrols2.conf</file></qresource></RCC>
I want to set the Style for my elements in qml. For that, I want to use a style like Material Style. Using the example which can be found under:
https://doc.qt.io/qt-5/qtquickcontrols2-material.html
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Controls.Material 2.12
ApplicationWindow {
visible: true
Material.theme: Material.Dark
Material.accent: Material.Purple
Column {
anchors.centerIn: parent
RadioButton { text: qsTr("Small") }
RadioButton { text: qsTr("Medium"); checked: true }
RadioButton { text: qsTr("Large") }
}
}
Gives me the result seen in the image I attached. No matter which Style I use, nothing changes.
I am currently using the newest free Qt version under a Windows 10 Os.
Can anyone help me? And is it possible to globally overwrite a Style and make an own Style, simply in QML.
As the docs points out:
To run an application with the Material style, see Using Styles in Qt Quick Controls.
There are several ways to set the style in Qt Quick Controls 2:
-
- add
QT += quickcontrols2
in your .pro and use#include <QQuickStyle>
andQQuickStyle::setStyle("Material");
in main.cpp
- add
-
- You can run from the console/CMD by adding the argument:
./your_executable -style material
. - If you use Qt Creator you can go to Projects-> Build & Run-> Run and in Command line arguments add:
-style material
.
- You can run from the console/CMD by adding the argument:
-
- You can run from the console/CMD:
QT_QUICK_CONTROLS_STYLE=material ./your_executable
- If you are using Qt Creator you can add it in the section Projects-> Build & Run-> Run-> Run Environment.
- or add
qputenv("QT_QUICK_CONTROLS_STYLE", "material");
in main.cpp.
- You can run from the console/CMD:
-
The qtquickcontrols2.conf file must be created:
[Controls] Style=Material
and must be in a qresource:
<RCC> <qresource prefix="/"> <file>main.qml</file> <file>qtquickcontrols2.conf</file> </qresource> </RCC>
这篇关于在 qml Qt 中设置样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!