简体   繁体   English

QML TextArea奇怪的填充

[英]QML TextArea strange padding

I have a TextArea. 我有一个TextArea。 If I set padding constantly padding working normally. 如果我设置填充不断填充正常工作。

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

If I uncomment lines above then I have strange behavior. 如果我取消注释上面的行,那么我有奇怪的行为。 What am I doing wrong? 我究竟做错了什么?

Screenshot 截图

It seems to be a bug, probably some updates are missing, when setting up the width of the contentItem of the ApplicationWindow , so the line lengths are not calculated properly. 在设置ApplicationWindowcontentItem的宽度时,似乎是一个错误,可能缺少一些更新,因此行长度计算不正确。

If you write: 如果你写:

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

You can see, that the parent.width is initially set to 0 and then changes to 640. When this change happens, there must be something going wrong with the signals. 您可以看到, parent.width最初设置为0,然后更改为640.当发生此更改时,信号必定存在问题。

A resize of the window will update the line lengths, so the proper layout is restored. 调整窗口大小将更新行长度,以便恢复正确的布局。 You might try to file a bugreport on http://bugreports.qt.io to have it fixed. 您可以尝试在http://bugreports.qt.io上提交bug报告以修复它。

Other than that, you may give an ID to your ApplicationWindow and use this instead of parent 除此之外,您可以为您的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