1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| // .cpp
#include "DropDownList.h"
#include <QGraphicsObject>
#include <QDeclarativeView>
#include <QDeclarativeContext>
DropDownList::DropDownList(QWidget *parent) :
QWidget(parent)
{
}
DropDownList::~DropDownList()
{
}
void DropDownList::build(QList<QObject*> list)
{
QDeclarativeView view(parentWidget());
QDeclarativeContext *ctxt = view.rootContext();
ctxt->setContextProperty("listItem", QVariant::fromValue(list));
ctxt->setContextProperty("style", style());
view.setSource(QUrl("qrc:/qml/DropDownList.qml"));
QGraphicsObject *dropDownList = view.rootObject();
dropDownList->setProperty("untitled", true);
dropDownList->setProperty("iconed", true);
}
QGraphicsObject* DropDownList::style()
{
QDeclarativeView styleview;
styleview.setSource(QUrl("qrc:/qml/style/Style.qml"));
QGraphicsObject *style = styleview.rootObject();
return style;
} |