Moving the list item delegate into its own QML file.
This commit is contained in:
@ -18,6 +18,7 @@ qt_add_qml_module(${TARGET_APP}
|
|||||||
QML_FILES
|
QML_FILES
|
||||||
Main.qml
|
Main.qml
|
||||||
QML_FILES ListPage.qml
|
QML_FILES ListPage.qml
|
||||||
|
QML_FILES ListItemDelegate.qml
|
||||||
)
|
)
|
||||||
|
|
||||||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
||||||
|
|||||||
19
ListItemDelegate.qml
Normal file
19
ListItemDelegate.qml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import QtQuick
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: myItem
|
||||||
|
required property string name
|
||||||
|
required property string info
|
||||||
|
property int fontSize: 16
|
||||||
|
|
||||||
|
width: parent.width
|
||||||
|
height: 40
|
||||||
|
Column {
|
||||||
|
Text {
|
||||||
|
text: '<b>Name:</b> ' + myItem.name
|
||||||
|
}
|
||||||
|
Text {
|
||||||
|
text: '<b>Info:</b> ' + myItem.info
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
ListPage.qml
22
ListPage.qml
@ -5,33 +5,15 @@ import QtQuick.Controls.Material
|
|||||||
Page {
|
Page {
|
||||||
id: page
|
id: page
|
||||||
|
|
||||||
Component {
|
|
||||||
id: contactDelegate
|
|
||||||
Item {
|
|
||||||
id: myItem
|
|
||||||
required property string name
|
|
||||||
required property string info
|
|
||||||
width: parent.width
|
|
||||||
height: 40
|
|
||||||
Column {
|
|
||||||
Text {
|
|
||||||
text: '<b>Name:</b> ' + myItem.name
|
|
||||||
}
|
|
||||||
Text {
|
|
||||||
text: '<b>Number:</b> ' + myItem.info
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
model: mainModel
|
model: mainModel
|
||||||
delegate: contactDelegate
|
delegate: ListItemDelegate {}
|
||||||
highlight: Rectangle {
|
highlight: Rectangle {
|
||||||
color: "lightsteelblue"
|
color: "lightsteelblue"
|
||||||
radius: 5
|
radius: 5
|
||||||
}
|
}
|
||||||
focus: true
|
focus: true
|
||||||
|
clip: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user