globally defining colors
-
I use it for global settings as well. In your qml files, you sometimes hardcode things like height or width of certain items. Your code is cross platforms, but not screens. Better to scale them according to screen sizes and these scaling factors can stored in a similar way.
-
I currently have two .qrc files, one for my fonts and one for my icons. Might it be preferable to have a "master" .qrc file, taking the place of these, and allowing me to declare my colors?
I've never really understood prefixes in the .qrc file. I always thought of it as sort of the QML analog to C++ namespaces. Is this accurate, and would I use prefixes to keep things organized in the file?
Thanks...
-
Trying to follow the approach here, but getting an "undefined" error when I try to use one of the colors in main.qml.
Colors.qml:
pragma Singleton import QtQuick 2.0 import QtQml Item { // the example calls for QtObject here, but Creator says "unknown component." property color accent: "#4147f0" ...
qml.qrc:
<RCC> <qresource prefix="/"> <file>Colors.qml</file> <file>main.qml</file> <file>qmldir</file> </qresource> </RCC>
qmldir:
singleton Colors Colors.qml
All my files are in the same directory. What am I doing wrong?
EDIT:
It might have something to do with my inability to use QtObject. It's not clear to me whether I need something that I didn't select in my installation. Where does this component "live?"
Thanks...
-
change item back to QtObject and do not worry about creator says
register the type in your main.cpp
qmlRegisterSingletonType( QUrl( "qrc:/Colors.qml" ), "zimmers.stylesheet", 1, 0, "Colors" );
import zimmers.stylesheet in any qml and
you can use it Colors.accent -
change item back to QtObject and do not worry about creator says
register the type in your main.cpp
qmlRegisterSingletonType( QUrl( "qrc:/Colors.qml" ), "zimmers.stylesheet", 1, 0, "Colors" );
import zimmers.stylesheet in any qml and
you can use it Colors.accent -
@JoeCFD thanks...that got rid of the warning, but my color isn't taking effect. Do I need to actually create a file zimmers.stylesheet, and if so, what should its contents be?
-
@mzimmers zimmers.stylesheet is only package name and can be anything, totally up to you.
add console.log in qml file to print its value