英文:
QML: ComboBox applying Material them
问题
I'm not able to set the dark material theme on combobox menù meanwhile it works on the combobox itself.
Some suggestion?
n.b I'm working on a larger project with QT Design Studio 4.2
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtMultimedia 5.15
import VenusView_UI 1.0
import QtGraphicalEffects 1.15
import QtQuick.Controls.Material 2.15
import QtQuick.Controls.Styles 1.4
Rectangle {
id: rectangle
width: Constants.width
height: Constants.height
color: "#2a2929"
border.width: 4
property bool rec_clicked: true
Material.theme: Material.Dark
Material.accent: Material.Indigo
ComboBox {
id: comboBox
x: 40
y: 425
displayText: "Resolution"
model: ListModel {
ListElement {
text: "4K"
}
ListElement {
text: "Full-HD"
}
ListElement {
text: "HD-Ready"
}
}
onActivated: {
comboBox.displayText = comboBox.currentText
console.log("Elemento selezionato: " + comboBox.currentText)
}
}
}
英文:
I'm not able to set the dark material theme on combobox menù meanwhile it works on the combobox itself.
Some suggestion?
n.b I'm working on a larger project with QT Design Studio 4.2
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtMultimedia 5.15
import VenusView_UI 1.0
import QtGraphicalEffects 1.15
import QtQuick.Controls.Material 2.15
import QtQuick.Controls.Styles 1.4
Rectangle {
id: rectangle
width: Constants.width
height: Constants.height
color: "#2a2929"
border.width: 4
property bool rec_clicked: true
Material.theme: Material.Dark
Material.accent: Material.Indigo
ComboBox {
id: comboBox
x: 40
y: 425
displayText: "Resolution"
model: ListModel{
ListElement{
text:"4K"
}
ListElement{
text:"Full-HD"
}
ListElement{
text:"HD-Ready"
}
}
onActivated: {
comboBox.displayText = comboBox.currentText
console.log("Elemento selezionato: " + comboBox.currentText)
}
}
}
答案1
得分: 1
这可能是一个bug,因为文档中提到:
> 所有属性都可以针对任何窗口或项目进行指定,并且它们会自动传播到子项,就像字体一样。
当这些属性没有在Window
或ApplicationWindow
上设置时,似乎传播到子项并不起作用。
这不仅仅是Qt Design Studio的问题,因为在Qt Creator中运行应用程序时,我也遇到了相同的错误行为。在您的情况下,解决方案是将这两行代码和必要的导入放入App.qml
中。
Material.theme: Material.Dark
Material.accent: Material.Indigo
英文:
This might be a bug, because the documentation states
> All attributes can be specified for any window or item, and they automatically propagate to children in the same manner as fonts.
It seems like the propagation to the children isn't working when those properties aren't set on Window
or ApplicationWindow
.
This isn't a Qt Design Studio only issue, because I get the same faulty behavior when running the application in Qt Creator as well. The solution in your case would be to put those two lines and the necessary import into App.qml
.
Material.theme: Material.Dark
Material.accent: Material.Indigo
答案2
得分: 1
Alternatively to setting the Material theme in code, you can also consider setting it via the special qtquickcontrols2.conf
and adding it to your application's resources.
[Controls]
Style=Material
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/">
<file>qtquickcontrols2.conf</file>
</qresource>
</RCC>
https://doc.qt.io/qt-5/qtquickcontrols2-configuration.html
英文:
Alternatively to setting the Material theme in code, you can also consider setting it via the special qtquickcontrols2.conf
and adding it to your application's resources.
[Controls]
Style=Material
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/">
<file>qtquickcontrols2.conf</file>
</qresource>
</RCC>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论