Change Font Size of Button in Qt QML

前端 未结 2 1410
没有蜡笔的小新
没有蜡笔的小新 2021-02-07 20:01

How can the font size of the text in a Button control be set in QML? The designer has not option, and \'font\' is not a valid property of Button.

Button {
    id         


        
2条回答
  •  一个人的身影
    2021-02-07 20:43

    You set the Button's style property:

    import QtQuick 2.2
    import QtQuick.Controls 1.2
    import QtQuick.Controls.Styles 1.2
    
    Rectangle {
      id: container
      width: 800
      height: 800
    
      Button {
        id: cmdQuit
        text: qsTr("Quit")
        width: 64
        height: 32
        style: ButtonStyle {
          label: Text {
            renderType: Text.NativeRendering
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignHCenter
            font.family: "Helvetica"
            font.pointSize: 20
            color: "blue"
            text: control.text
          }
        }
      }
    }
    

提交回复
热议问题