旋转的QML文本:具有基线锚点的位置

时间:2018-06-13 08:24:13

标签: qt qml

我需要相对于矩形定位旋转的Text元素。这是一个例子:

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import QtQuick.Window 2.2

ApplicationWindow {
  visible: true
  width: 640
  height: 480
  title: qsTr("Hello World")

  Rectangle {
    id: rectangle
    x: 180
    y: 99
    width: 200
    height: 200
    color: "#b73131"

    Text {
      id: text1
      x: -112
      y: 85
      text: qsTr("Text")
      rotation: -90
      anchors.right: parent.left
      anchors.rightMargin: 20
      font.pixelSize: 12
    }

    Text {
        id: text2
        x: -46
        y: 160
        text: qsTr("Textg")
        font.pixelSize: 12
        rotation: -90
        anchors.right: parent.left
        anchors.rightMargin: 20
    }
  }
}

但是,我希望text1text2共享相同的基线(在上面的示例中不会发生这种情况,因为g字符低于基线,因此右边缘这两个文本是不同的)。如何将baseline锚点用于旋转文本?

1 个答案:

答案 0 :(得分:1)

您可以更改旋转原点。我想这会给你想要的结果:

func changelogPopup(){
    let changeLog1 = UIAlertController(title: "CHANGELOG", message: "Veuillez choisir la version pour laquelle vous souhaitez voir le changelog :", preferredStyle: .alert)
    changeLog1.addAction(UIAlertAction (title: "Continuer", style: .default, handler: { (UIAlertAction) in

        let field = changeLog1.textFields?[0] as! UITextField

        if field.text == "1"{ 
            self.changeLog1P()
        }

    }))
    changeLog1.addAction(UIAlertAction(title: "Annuler et sortir", style: .cancel, handler: nil))

    changeLog1.addTextField { (textField) in
        textField.placeholder = "Numéro de Build de la version"
    }

    self.present(changeLog1, animated: true, completion: nil)
}