【问题标题】:TextArea problematic background QML QTTextArea 有问题的背景 QML QT
【发布时间】:2018-12-17 22:46:46
【问题描述】:

尝试不同的代码组合并部分解决我的问题我遇到了一种我无法完全解释的行为。因此,当我创建一个没有 Scrollview 的简单 TextArea 时,它看起来像这样:

RowLayout  {
    id: rowLayout
    Rectangle{                       
        height: 50
        width: 295
        TextArea {
            id: textArea
            text: (" message...")
           wrapMode: Text.WrapAnywhere
           anchors.fill: parent
        }                
    }

文本区域创建默认背景。现在我想用 ScrollView 做 TextArea 也用默认的 TextArea 背景,但结果是这样的:

RowLayout  {
    id: rowLayout
    Rectangle{
       height: 50
        width: 295
    ScrollView {
       id: scrollView1
        anchors.fill: parent

    TextArea {
            id: textArea
            text: (" message...")
           wrapMode: Text.WrapAnywhere                           
        }
    }
}

设置默认 TextArea 背景的唯一机会是设置implicitHeight,implicitWidth,但是在将文本输入到 TextArea 直到出现滚动条之后,背景通过像这样在其他组件后面延伸到整个长度:

RowLayout  {
    id: rowLayout
    Rectangle{
        //color: "#00000000"
       height: 50
        width: 295
    ScrollView {
       id: scrollView1
        anchors.fill: parent
    TextArea {
            id: textArea
            text: (" message...")
           wrapMode: Text.WrapAnywhere
              implicitHeight: 50
              implicitWidth: 295
        }
    }
}

所以我唯一想要的是一个可滚动的文本区域,但使用这个黑色的默认背景,而不是我可以用矩形做的背景。 任何人都可以看看吗? 谢谢你:)

【问题讨论】:

    标签: qt qml qtquickcontrols2 qtquick-designer


    【解决方案1】:

    我尽力了。检查下面的示例,希望对您有所帮助=)

    import QtQuick 2.9
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.2
    import QtQuick.Layouts 1.3
    
    ApplicationWindow {
        visible: true
    
        width: 400
        height: 400
    
        RowLayout {
            width: 295
            height: 50
    
            anchors.centerIn: parent
    
            ScrollView {
                Layout.fillHeight: true
                Layout.fillWidth: true
    
                background: Rectangle { color: "black" }
    
                TextArea {
                    id: messageField
    
                    placeholderText: qsTr("message...")
    
                    color: "white"
    
                    wrapMode: TextArea.WrapAnywhere
                }
            }
        }
    }
    

    结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多