簡體   English   中英

qml中如何顯示居中的內容?

[英]How to show the content in the center in qml?

您好,我正在使用 qml 開發移動應用程序,它有不同的圖標、按鈕、標簽、文本等。所以我希望我的應用程序適合每個屏幕尺寸。 所以我需要在設備的中心顯示這些元素。 我使用過 anchor.centerIn:parent 但是當我在第二個元素上使用它時,第一個元素被第二個元素覆蓋。 這是我的例子

Page {
id:page
Rectangle{
    anchors.fill: parent
    color: "#8d6d89"
    Label{
        anchors.centerIn: parent
        font.pixelSize: app.titleFontSize
        font.bold: true
        wrapMode: Text.Wrap
        padding: 16*app.scaleFactor
        text: "TESTING PAGE"
    }
    Button{
        id:btn
        height: 40*scaleFactor
        width: 200*scaleFactor
        text: "CLICK HERE"
        anchors.centerIn: parent
        anchors.topMargin: 20*app.scaleFactor
    }
}

}

而不是這個:

anchors.topMargin: 20*app.scaleFactor

試試這個:

anchors.verticalCenterOffset: 20*app.scaleFactor

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM