文本区域有问题的背景QML QT
尝试不同的代码组合并部分解决我的问题时,我遇到了一个无法完全解释的行为。因此,当我创建一个没有Scrollview的简单文本区域时,它看起来是这样的:文本区域有问题的背景QML QT,qt,qml,qtquickcontrols2,qtquick-designer,Qt,Qml,Qtquickcontrols2,Qtquick Designer,尝试不同的代码组合并部分解决我的问题时,我遇到了一个无法完全解释的行为。因此,当我创建一个没有Scrollview的简单文本区域时,它看起来是这样的: RowLayout { id: rowLayout Rectangle{ height: 50 width: 295 TextArea { id: textArea text: (" me
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
}
}
}
所以我唯一想要的是一个可滚动的文本区域,但是有这个黑色的默认背景,而不是我可以用矩形做的背景。
有人能看一下吗?
谢谢:)我尽力了。检查下面的示例,希望对您有所帮助=) 结果:
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
}
}
}
}