16,173
社区成员
发帖
与我相关
我的任务
分享
#include <QGuiApplication>
#include <qqmlengine.h>
#include <qqmlcontext.h>
#include <qqml.h>
#include <QtQuick/qquickitem.h>
#include <QtQuick/qquickview.h>
#include "dataobject.h"
/*
This example illustrates exposing a QList<QObject*> as a
model in QML
*/
//![0]
int main(int argc, char ** argv)
{
QGuiApplication app(argc, argv);
QList<QObject*> dataList;
dataList.append(new DataObject("Item 1"));
dataList.append(new DataObject("Item 2"));
dataList.append(new DataObject("Item 3"));
dataList.append(new DataObject("Item 4"));
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
QQmlContext *ctxt = view.rootContext();
ctxt->setContextProperty("item1.ebklist.ebkmodel", QVariant::fromValue(dataList));
//![0]
view.setSource(QUrl("qrc:view.qml"));
view.show();
return app.exec();
}
Item{
id: item1
x: 0
y: 0
width: 800
height: 480
visible: true
Image {
id: image_b
visible: true
anchors.fill: parent
source: "image/bg_list.jpg"
}
Component {
id: highlight
Rectangle {
color: "lightsteelblue"
radius: 5
}
}
Component{
id: ebkdelegate
Item {
x: parent.x
width: list_ebk.width
height: 43
MouseArea{
anchors.fill: parent
// onClicked:;
}
Row {
id: row1
Rectangle {
width: list_ebk.width
height: parent.parent.height
color: "transparent"
}
}
Text {
text: name
font.bold: true
anchors.verticalCenter: parent.verticalCenter
}
}
}
ListView {
id: ebklist
x: 17
y: 119
width: 677
height: 343
delegate:ebkdelegate
spacing: 7
model: ListModel{
id: ebkmodel
}
highlight: highlight
}
}