[英]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.