I'm developping a QtQuick Custom Style (according too this documentation), and I'm facing a problem.
My Button template implementation expose an additionnal user property
MyCustomStyle/Button.qml
import QtQuickimport QtQuick.Controlsimport QtQuick.Templates as TT.Button { id: control enum ButtonVariations { Giant, Regular, Small } property int variation : Button.ButtonVariations.Regular //...}
The problem is that when I use a Button
in my application, it will load either this Button template definition, or another one, depending on the style choosen for the app.This result in an error in qml
MyApp/SomePage.qml
ComboBox { id: comboBox width: 140 height: 25 model: ["Giant", "Regular", "Small"] } Button { Layout.alignment: Qt.AlignRight | Qt.AlignTop text: "Normal" implicitWidth: 100 variation : comboBox.currentIndex //error : Invalid property name "variation" (M16) }
When I run the app, it works great, and the button reacts according to the property. But due to this error, Qt Design Studio cannot parse the file, and cannot adapt views.
Question : Is it possible to assign this property as an "optionnal" property in QML ?
I've already tried this, unsuccesfully :
1 - Check if property exists (according to this topic)
variation ? variation : comboBox.currentIndex //Do not works
-> this syntax doesn't seems to exists
2 - Re-declare property in the instantiation (so it could overrides or first-declare the property)
Button { id: myButton property int variation : comboBox.currentIndex //Do not works}
-> This compile and doesn't generate error, but it's like if the property inside the T.Button
isn't binded anymore. Nothing reacts
EDIT :3 - Try to use a simple Binding type as follow (thanks to smr's comment)
Binding { variation: comboBox.currentIndex}
-> Generate an error at runtime. Component cannot be loaded