QML: comparta valores de color y otros valores de solo lectura en varios archivos QML
Estoy buscando una manera simple de compartir valores de solo lectura en múltiples archivos QML, por ejemplo; Digamos que tengo un elemento de etiqueta:
Label {
id: titleLabel
text: listView.currentItem ? listView.currentItem.text : "IDEAL Networks"
font.pixelSize: 20
elide: Label.ElideRight
horizontalAlignment: Qt.AlignLeft
verticalAlignment: Qt.AlignVCenter
Layout.fillWidth: true
color: red;
padding: {
left: 14
}
}
loscolor
ypadding
los valores deben usarse en otros archivos QML y otras áreas del mismo archivo.
En lugar de volver a escribirred
y 14 en varias ubicaciones, ¿hay alguna forma de crear una biblioteca compartida que contenga estos valores para facilitar la actualización global en una fecha posterior?
* Actualización *
He seguido las instrucciones aquí:http://doc.qt.io/qt-5/qtqml-modules-qmldir.html
Sin embargo, cuando importo la costumbreCustomStyles 1.0
módulo recibo un error - el módulo "CustomStyles" no está instalado.
//Style.qml with custom singleton type definition
pragma Singleton
import QtQuick 2.0
QtObject {
property int textSize: 20
property color textColor: "green"
}
// qmldir declaring the singleton type
module CustomStyles
singleton Style 1.0 Style.qml
// singleton type in use
import QtQuick 2.0
import CustomStyles 1.0
Text {
font.pixelSize: Style.textSize
color: Style.textColor
text: "Hello World"
}