您的位置:首页 > 其它

创建第一个QML工程(学习中)

2013-04-11 09:08 281 查看
main.cpp

#include "mainwindow.h"

#include <QApplication>
#include <QDeclarativeView>
#include <QDeclarativeContext>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QDeclarativeView view;
QDeclarativeContext *context = view.rootContext();
context->setContextProperty("backgroundColor",
QColor(Qt::yellow));

view.setSource(QUrl::fromLocalFile("main.qml"));
view.show();

return app.exec();
}
main.qml

import QtQuick 1.1

Rectangle {
width: 100
height: 62
color:backgroundColor
Text {
anchors.centerIn: parent
text: "Hello Yellow World!"
}
}

截图效果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: