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. [SOLVED] No text with ButtonStyle

[SOLVED] No text with ButtonStyle

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 893 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.
  • M Offline
    M Offline
    morker
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • shavS Offline
      shavS Offline
      shav
      wrote on last edited by
      #2

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

      }
      @

      Mac OS and iOS Developer

      1 Reply Last reply
      0
      • M Offline
        M Offline
        morker
        wrote on last edited by
        #3

        Thanks, that works!

        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