簡體   English   中英

QML TextArea奇怪的填充

[英]QML TextArea strange padding

我有一個TextArea。 如果我設置填充不斷填充正常工作。

import QtQuick 2.9
import QtQuick.Controls 2.2

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

    TextArea{
        font.pixelSize: 20
        anchors.fill: parent
        wrapMode: TextArea.Wrap
        leftPadding: 100 //*parent.width/640
        rightPadding: 100 //*parent.width/640
    }
}

如果我取消注釋上面的行,那么我有奇怪的行為。 我究竟做錯了什么?

截圖

在設置ApplicationWindowcontentItem的寬度時,似乎是一個錯誤,可能缺少一些更新,因此行長度計算不正確。

如果你寫:

leftPadding: {
    console.log(parent, parent.width)
    return 100 * parent.width/640
}

您可以看到, parent.width最初設置為0,然后更改為640.當發生此更改時,信號必定存在問題。

調整窗口大小將更新行長度,以便恢復正確的布局。 您可以嘗試在http://bugreports.qt.io上提交bug報告以修復它。

除此之外,您可以為您的ApplicationWindow提供一個ID ,並使用它而不是parent

import QtQuick 2.7
import QtQuick.Controls 2.0

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

    TextArea{
        font.pixelSize: 20
        anchors.fill: parent
        wrapMode: TextArea.Wrap
        leftPadding: 100 * win.width/640
        rightPadding: 100 * win.width/640
    }
}

暫無
暫無

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

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