[英]TextArea problematic background QML QT
尝试不同的代码组合并部分解决了我的问题,我遇到了一种我无法完全解释的行为。 因此,当我创建一个没有Scrollview的简单TextArea时,它看起来像这样:
RowLayout {
id: rowLayout
Rectangle{
height: 50
width: 295
TextArea {
id: textArea
text: (" message...")
wrapMode: Text.WrapAnywhere
anchors.fill: parent
}
}
文本区域创建默认背景。 现在,我想使用ScrollView ALSO和默认的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背景的唯一机会是设置hiddenHeight,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
}
}
}
因此,我唯一想要的是可滚动的textarea,但是具有此黑色默认背景,而不是我可以用矩形完成的背景。 谁能看一看? 谢谢 :)
我尽力了。 查看下面的示例,希望对您有所帮助=)
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
}
}
}
}
结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.