I have some problem with popup window size behavior using Qt Quick Controls 2. When I'm putting ListView as contentItem for Popup window, Popup window size is zero. Some sample code that reproduce issue:
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
}
}
}
}
}
How to make popup adopt to the size of ListView?
contentWidth
/contentHeight
? – folibiscontentItem
just do nothing. According to the docs:If only a single item is used within a Popup, it will resize to fit the implicit size of its contained item
– folibiswidth: contentWidth; height: contentHeight
) and simultaneously set the size ofcontentItem
to that. – folibiswidth: contentWidth
height: contentHeight
both forPopup
andListView
still has zero size.contentWidth
contentHeight
parameters forPopup
andListView
isn't the same.contentWidth
contentHeight
parameters forListView
is the size of delegates, forPopup
it is size of ListView. – Kamil Zaripov