在QT 5.15中为圆形按钮添加文本



尝试为圆形按钮添加文本。给出错误'Cannot assign to不存在的属性:text'。

RoundButton {
id: circ1
text: qsTr("RoundButton")
anchors.right:          parent.right
anchors.rightMargin:    1.0 * ScreenTools.defaultFontPixelWidth
anchors.topMargin:      1.0 * ScreenTools.defaultFontPixelHeight
anchors.top:            parent.top
Layout.alignment:       Qt.AlignHCenter
//radius:                 120
width:                  60
height:                 60
contentItem: Text {
text: "Plan"
}
//font.pointSize:         ScreenTools.smallFontPointSize * ScreenTools.smallFontPointRatio
}

代码在没有text属性的情况下按预期工作。它也适用于具有text属性的普通按钮。我的印象是圆形按钮应该和普通按钮一样。你知道我哪里出错了吗?

我无法重新创建您的问题。几件事:

  1. 您有布局。对准和锚。这些是不相容的相信
  2. roundButton的文本不被使用,因为您已经设置了contentItem设置为静态Text{} Item,而不是将其中的文本设置为circ1.text

最新更新