文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>QT: c++ 中通过objectName访问qml中的对象

QT: c++ 中通过objectName访问qml中的对象

时间:2010-10-16  来源:wumao2

=================================================
// c++
=================================================
#include <QApplication>
#include <QDeclarativeView>
#include <QDeclarativeContext>
#include <QObject>
#include <QGraphicsObject>
#include <QDeclarativeItem>


int main(int argc, char *argv[]) { QApplication app(argc, argv); QDeclarativeView view; view.setSource(QUrl::fromLocalFile("main.qml")); view.show(); QDeclarativeItem *item = view.rootObject()->findChild<QDeclarativeItem*>("myRect"); if (item) { item->setProperty("color", QColor(Qt::yellow)); } return app.exec(); }

====================================
// qml 界面显示 main.qml
===================================
import Qt 4.7 Item { width: 200; height: 200 Rectangle { anchors.fill: parent color: "red" objectName: "myRect" } }




相关阅读 更多 +
排行榜 更多 +
Unity Connect

Unity Connect

学习教育 下载
青橙记录本

青橙记录本

商务办公 下载
脑洞惊魂夜

脑洞惊魂夜

休闲益智 下载