[SOLVED] No text with ButtonStyle



  • Hi,

    why is "Test" displayed and not "button 1" and "button 2"? I got the same result if I remove "text: "Test" "...

    Test.qml:

    @import QtQuick 2.3
    import QtQuick.Controls 1.2
    import QtQuick.Controls.Styles 1.2

    Rectangle {
    id: rectangle1
    width: 800
    height: 600

    Button {
        text: "button 1"
        style: ClientButtonStyle {}
    }
    
    Button {
        x: 169
        y: 0
        text: "button 1"
        style: ClientButtonStyle {}
    }
    

    }
    @

    ClientButtonStyle.qml:

    @
    import QtQuick 2.3
    import QtQuick.Controls.Styles 1.2

    ButtonStyle {
    label: TimelineTextStyle {
    text: "Test"
    verticalAlignment: Text.AlignVCenter
    horizontalAlignment: Text.AlignHCenter
    }

    background: Rectangle {
        radius: 4
        implicitHeight: 80
    
        gradient: Gradient {
            GradientStop { position: 0 ; color: control.pressed ? "#019875" : "#16A085" }
            GradientStop { position: 1 ; color: control.pressed ? "#019875" : "#16A085" }
        }
    }
    

    }
    @

    TimelineTextStyle.qml:

    @
    import QtQuick 2.0

    Text {
    color: "#FFFFFF"
    font.pointSize: 20
    font.family: "Helvetica Neue"
    opacity: 0.70
    }
    @

    Thanks



  • Hi,

    In your ClientButtonStyle.qml file you set static text as "test". If you want use text from button text you need use "control.text" and your file must looks like:
    @
    import QtQuick 2.3
    import QtQuick.Controls.Styles 1.2

    ButtonStyle {
    label: TimelineTextStyle {
    text: control.text //This is correct
    verticalAlignment: Text.AlignVCenter
    horizontalAlignment: Text.AlignHCenter
    }

    background: Rectangle {
        radius: 4
        implicitHeight: 80
    
        gradient: Gradient {
            GradientStop { position: 0 ; color: control.pressed ? "#019875" : "#16A085" }
            GradientStop { position: 1 ; color: control.pressed ? "#019875" : "#16A085" }
        }
    }
    

    }
    @



  • Thanks, that works!


Log in to reply
 

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