How do I find out values for QML enumerations in docs?
Unsolved
QML and Qt Quick
-
Example case:
I use the TextEdit QML type, and want to set horizontalAlignment and verticalAlignment from C++ via property binding.Docs state:
Valid values for horizontalAlignment are: TextEdit.AlignLeft (default) TextEdit.AlignRight TextEdit.AlignHCenter TextEdit.AlignJustify Valid values for verticalAlignment are: TextEdit.AlignTop (default) TextEdit.AlignBottom TextEdit.AlignVCenter
The values are not linked, nor is a C++-side Enumeration mentioned. How do I find out which values to use? What type should the Q_PROPERTY have?
-
They should refer to the Qt AlignmentFlag enum.
Therefore, you should be able to do something like this:Q_PROPERTY(int hAlign READ getHorizontalAlignment NOTIFY objectChanged) Q_PROPERTY(int vAlign READ getVerticalAlignment NOTIFY objectChanged)
int MyClass::getHorizontalAlignment() { return Qt::AlignHCenter; } int MyClass::getVerticalAlignment() { return Qt::AlignBottom; }
TextEdit { anchors.fill: parent text: "Hello World" horizontalAlignment: MyContextPropertyOrModel.hAlign verticalAlignment: MyContextPropertyOrModel.vAlign }