Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

Default Style override to avoid setting style on each widget

$
0
0
Hi, I manage to get custom style working, I made all of them as Component into a single file to have a single point for the style. I can now put the style into a loader and bind the current style into the widget. But every button, slider, combo box,… I create I have to apply the style (1 extra line each time), I could create a custom Button component but that would just make an obfuscate layer in my mind. I was wondering, if it’s possible to change the default style apply to widgets (or at least change the one into the Component that is used to create the future widget). See the line I want to avoid into the Application.qml part. This is a simplified version (would like to keep dynamic style, without having to set the style on each widget individually and keep the QtQuickControl widget Component name). It’s probably impossible right now, but I just wanted to make sure I was not missing something somewhere. // MyStyle.qml Item {  id: component           property Component slider:   SliderStyle   {    groove:     Rectangle     {      implicitWidth: 200      implicitHeight: 8      color: component.fillColor      radius: 8     }    handle:     Rectangle     {      ...     }    tickmarks:     ...   }      property Component button:             ButtonStyle             { ... } }   // Application.qml Rectangle { property var defaultStyle: MyStyle {} property string fileName: '' property var uiStyle: styleLoaded ? styleLoader_.item : defaultStyle property bool styleLoaded: styleLoader_.status == Component.Ready   onFileNameChanged:  {   styleLoader_.sourceComponent = Qt.createComponent(component.fileName);  }    Loader  {   id: styleLoader_  }       Button     {  style: uiStyle.button   // Line I want to avoid         ...     }       Slider     {         style: uiStyle.slider   // Line I want to avoid         ...     } }

Viewing all articles
Browse latest Browse all 4972

Trending Articles