Qt 旋转的QML文本:使用基线定位点定位

Qt 旋转的QML文本:使用基线定位点定位,qt,qml,Qt,Qml,我需要定位相对于矩形旋转的文本元素。这里有一个例子: 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: rectang

我需要定位相对于矩形旋转的
文本
元素。这里有一个例子:

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

但是,我希望
text1
text2
共享相同的基线(在上述示例中不会发生这种情况,因为
g
字符位于基线下方,因此两个文本的右边缘不同)。如何使用旋转文本的
基线
锚定?

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

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
      transform: Rotation { origin.x: text1.width; origin.y: 0; angle: -90}
    }

    Text {
        id: text2
        x: -46
        y: 160
        text: qsTr("Textg")
        font.pixelSize: 12
        //rotation: -90
        anchors.right: parent.left
        anchors.rightMargin: 20
        transform: Rotation { origin.x: text2.width; origin.y: 0; angle: -90}
    }
  }
}

是的。你能解释一下旋转时锚的意思吗?另外,如果我想让垂直中心位于矩形的垂直中心,我需要添加什么?锚点总是影响元素的边界框。想象一下旋转文本周围有一个边框。我不太明白你说的垂直中心是什么意思!你能澄清或张贴一张你希望最终结果是什么样子的图片吗?我的意思是:锚在旋转之前或之后会影响元素的边界框吗?在旋转之后,我的垂直中心问题就解决了