Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Default Style override to avoid setting style on each widget
QtWS25 Last Chance

Default Style override to avoid setting style on each widget

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 881 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JeromeGodbout
    wrote on last edited by
    #1

    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
        ...
    }
    

    }
    @

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved