Access QML enumeration from C++
Hi,
I have a Text Item that uses different kinds of Alignment and must be able to take this information from a C++ model. For example, I want to be able to set:
Code:
delegate: Text {
verticalAlignment: model.alignment // Text.AlignVCenter, Text.AlignTop or Text.AlignBottom
...
}
I have not found anything about this in the docs (there is some stuff for "the other way 'round", for exposing c++ enums to QML of course)
Is there a "best practice" for handling this problem?
Re: Access QML enumeration from C++
Those enum value are from a C++ enum, Qt::AlignmentFlag
You could try letting the model return the respective Qt::AlignmentFlag value
Cheers,
_
Re: Access QML enumeration from C++
Cool, you are absolutely right! How did you know (apart from: you just awesomely did :cool:)?
Where can I find such information in similar cases?
I didn't succeed in finding any relevant source of information about these connections.
Re: Access QML enumeration from C++
Everything in QML, aside from its keywords and primitive types, comes from C++.
So any enum value must have been exported from C++.
Since Qt has alignment flags in its C++ API, it was a logical conclusion that these would be the same values that got exported to QML.
Cheers,
_