Controls 1.4: Partially changing control style without discarding system palette



  • Hi,

    had no luck so far at stackoverflow, so I'm crossposting it here.

    I want to partially change the style of a control without affecting it's rendering otherwise. Let's take a button as an example and create a MyButton.qml containing:

    Button {
        id: mybutton
    
        style: ButtonStyle {
              label: Text {
                renderType: Text.NativeRendering
                font.family: "Helvetica"
                font.pointSize: 20
                text: control.text
              } 
        }
    }
    

    Expected: a system theme colored button with an ugly font in it.
    Got: default-styled button ignoring the system palette (while the rest of the application is themed fine)
    example

    Why does the overriding style ignore the system palette? What is the right way to do it?


  • Moderators

    @EvilMav AFAIK overriding the style removes the default style. One way to make partial changes is to directly change in the source as described here

    The second way to create the button is good if you plan to use your rounded button in several places. It involves moving the code into its own QML file within your project.
    For this approach, we'll copy the background code from the default style's Button.qml. This file can be found in the following path in your Qt installation:
    $QTDIR/qml/QtQuick/Controls.2/Button.qml


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.