Creating QQuick Items from C++
-
Hi!!
Can i make this:
QML:
Button { id: myButton x: 200 y: 400 width: 200 height: 30 text: "Push me" }
...but from C++ ?
I mean, i'm not looking to create a QPushButton but a QQuick Button but from C++... somehow transcribe my QML document into C++ .. If so, can you show an example?
Thanks in advance....
-
Are you trying to instantiate a QML-defined component from C++?
QQmlComponent, which can be passed a URL to a file, or a byte array containing the source via the setData function.If the goal is to create the button purely from C++, there's the direct use of the scene graph APIs, or QQuickPaintedItem for an API similar to Qt widgets.
Transcribing suggests that this involves a working program.
If this is a performance concern, have you seen the QML profiler built into Creator? Or is this a source obfuscation situation? There is some compilation into a binary format or C++ that also helps decrease load time. I don't know the current state.
-
Are you trying to instantiate a QML-defined component from C++?
QQmlComponent, which can be passed a URL to a file, or a byte array containing the source via the setData function.If the goal is to create the button purely from C++, there's the direct use of the scene graph APIs, or QQuickPaintedItem for an API similar to Qt widgets.
Transcribing suggests that this involves a working program.
If this is a performance concern, have you seen the QML profiler built into Creator? Or is this a source obfuscation situation? There is some compilation into a binary format or C++ that also helps decrease load time. I don't know the current state.
-
hi, QSceneGraph is what i was looking for... i preffer c++ always..
according to what i was looking, Scene Graph is faster than PaintedItems..thanks.
@1XU7 Just means doing everything from scratch. There is no "inherit from QML Button" in C++
The learning curve is pretty steep, examples are rare. -
@1XU7 Just means doing everything from scratch. There is no "inherit from QML Button" in C++
The learning curve is pretty steep, examples are rare.@Asperamanca Also, for UI handling from C++, you'll want to add your own event filter.
-
@1XU7 Just means doing everything from scratch. There is no "inherit from QML Button" in C++
The learning curve is pretty steep, examples are rare.Sounds like you tried it, but didn't like the outcome?
-
Sounds like you tried it, but didn't like the outcome?
@Pl45m4 SceneGraph has it's uses for custom components.
An event filter on the C++ side is useful because you can enforce common event handling rules across all components.
Building a scene dynamically from C++ using prefabricated QML-building blocks has it's use cases.But I wouldn't start writing basic QML UI via C++.
-
@Pl45m4 SceneGraph has it's uses for custom components.
An event filter on the C++ side is useful because you can enforce common event handling rules across all components.
Building a scene dynamically from C++ using prefabricated QML-building blocks has it's use cases.But I wouldn't start writing basic QML UI via C++.
I'm just curious, because I've never heard of it and usually you would design the QuickItems in their QMLanguage on QtQuick side and then connect your C++ code to it