Kam*_*pov 0 qt qml qt-quick qtquick2 qtquickcontrols2
我使用Qt Quick Controls 2时出现弹出窗口大小行为的问题.当我将ListView作为弹出窗口的contentItem时,弹出窗口大小为零.一些重现问题的示例代码:
import QtQuick 2.4
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
ApplicationWindow {
id: window
visible: true
width: 800
height: 600
Button {
text: "open popup"
onClicked: popup.open()
}
Popup {
id: popup
x: (window.width - width) / 2
y: window.height / 6
width: contentWidth
height: contentHeight
contentItem: ListView {
width: contentWidth
height: contentHeight
model: ListModel {
ListElement {
name: "Apple"
cost: 2.45
}
ListElement {
name: "Orange"
cost: 3.25
}
ListElement {
name: "Banana"
cost: 1.95
}
}
delegate: RowLayout {
Label {
text: name
}
Label {
text: cost
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何使弹出窗口采用ListView的大小?
垂直ListView不提供内容宽度.它始终是-1.你必须指定一些东西,例如:
Popup {
id: popup
x: (window.width - width) / 2
y: window.height / 6
contentItem: ListView {
implicitWidth: 200 // <==
implicitHeight: contentHeight
//...
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1031 次 |
| 最近记录: |