I'm trying to make a QtQuick app with color themes. I plan to make a few .qml style sheets that define concepts like buttonColor, fontColor and so on. Here's an example of what the style sheets will look like more or less:
pragma Singletonimport QtQuickQtObject { property color bodyTextColor: "white" property color headerTextColor: "black" property int buttonBorderWidth: 3 property color buttonColor: "#007bff" property color backgroundColor: "#000000" property color accentColor: "#6c757d" property int fontSize: 16 property int titleFontSize: fontSize + 8 property int labelFontSize: fontSize - 16}
I tried import "ClassicStylesheet.qml" as Styles
and it can't find it even though it's in the same root directory with Main.qml (I get a "no such directory" error). Using an absolute path to ClassicStylesheet.qml gets around this and the app runs, but it still doesn't work. I get the following error:
Could not find any constructor for value type QQuickColorValueType to call with value QVariant(QObject*, 0x0)qrc:/[projectname]/Main.qml:31:17: Unable to assign undefined to QColor
All components render in black when running with an absolute path to the style sheet. Here's an example of my Main.qml file using my reusable LargeButton component (which renders fine using defaults, without the stylesheet) to create a main menu button:
import QtQuickimport QtQuick.Controlsimport QtQuick.Layoutsimport "ClassicStylesheet.qml" as StylesWindow { width: 1280 height: 720 visible: true title: qsTr("Test") Rectangle { id: menuFrame width: 600 height: 400 color: "lightgrey" anchors.centerIn: parent radius: 25 ColumnLayout { anchors.centerIn: parent spacing: 10 LargeButton { text: "Settings" buttonColor: Styles.buttonColor accentColor: Styles.accentColor fontColor: Styles.fontColor onClicked: { } } } }}
Any advice on navigating this? Why doesn't it recognize my file or read its contents? Thanks.