本文整理汇总了C++中QQuickView::rootObject方法的典型用法代码示例。如果您正苦于以下问题:C++ QQuickView::rootObject方法的具体用法?C++ QQuickView::rootObject怎么用?C++ QQuickView::rootObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QQuickView
的用法示例。
在下文中一共展示了QQuickView::rootObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nested
void tst_qquickfocusscope::nested()
{
QQuickView *view = new QQuickView;
view->setSource(testFileUrl("test2.qml"));
QQuickFocusScope *item1 = findItem<QQuickFocusScope>(view->rootObject(), QLatin1String("item1"));
QQuickFocusScope *item2 = findItem<QQuickFocusScope>(view->rootObject(), QLatin1String("item2"));
QQuickFocusScope *item3 = findItem<QQuickFocusScope>(view->rootObject(), QLatin1String("item3"));
QQuickFocusScope *item4 = findItem<QQuickFocusScope>(view->rootObject(), QLatin1String("item4"));
QQuickFocusScope *item5 = findItem<QQuickFocusScope>(view->rootObject(), QLatin1String("item5"));
QVERIFY(item1 != 0);
QVERIFY(item2 != 0);
QVERIFY(item3 != 0);
QVERIFY(item4 != 0);
QVERIFY(item5 != 0);
view->show();
view->requestActivate();
QTest::qWaitForWindowActive(view);
QTRY_VERIFY(view == qGuiApp->focusWindow());
QVERIFY(item1->hasActiveFocus() == true);
QVERIFY(item2->hasActiveFocus() == true);
QVERIFY(item3->hasActiveFocus() == true);
QVERIFY(item4->hasActiveFocus() == true);
QVERIFY(item5->hasActiveFocus() == true);
delete view;
}
示例2: signalEmission
void tst_qquickfocusscope::signalEmission()
{
QQuickView *view = new QQuickView;
view->setSource(testFileUrl("signalEmission.qml"));
QQuickRectangle *item1 = findItem<QQuickRectangle>(view->rootObject(), QLatin1String("item1"));
QQuickRectangle *item2 = findItem<QQuickRectangle>(view->rootObject(), QLatin1String("item2"));
QQuickRectangle *item3 = findItem<QQuickRectangle>(view->rootObject(), QLatin1String("item3"));
QQuickRectangle *item4 = findItem<QQuickRectangle>(view->rootObject(), QLatin1String("item4"));
QVERIFY(item1 != 0);
QVERIFY(item2 != 0);
QVERIFY(item3 != 0);
QVERIFY(item4 != 0);
view->show();
view->requestActivate();
QTest::qWaitForWindowActive(view);
QTRY_VERIFY(view == qGuiApp->focusWindow());
QVariant blue(QColor("blue"));
QVariant red(QColor("red"));
item1->setFocus(true);
QCOMPARE(item1->property("color"), red);
QCOMPARE(item2->property("color"), blue);
QCOMPARE(item3->property("color"), blue);
QCOMPARE(item4->property("color"), blue);
item2->setFocus(true);
QCOMPARE(item1->property("color"), blue);
QCOMPARE(item2->property("color"), red);
QCOMPARE(item3->property("color"), blue);
QCOMPARE(item4->property("color"), blue);
item3->setFocus(true);
QCOMPARE(item1->property("color"), blue);
QCOMPARE(item2->property("color"), red);
QCOMPARE(item3->property("color"), red);
QCOMPARE(item4->property("color"), blue);
item4->setFocus(true);
QCOMPARE(item1->property("color"), blue);
QCOMPARE(item2->property("color"), red);
QCOMPARE(item3->property("color"), blue);
QCOMPARE(item4->property("color"), red);
item4->setFocus(false);
QCOMPARE(item1->property("color"), blue);
QCOMPARE(item2->property("color"), red);
QCOMPARE(item3->property("color"), blue);
QCOMPARE(item4->property("color"), blue);
delete view;
}
示例3: main
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
// If you want to use an engine, this shows how to get an UI Element!:
// QQmlApplicationEngine engine;
// engine.load(QUrl(QStringLiteral("qrc:/game.qml")));
// QObject root = engine.rootObjects().first();
// QObject element = root.findChild("element");
// element.setProperty("color","red");
//Creating Objects from Qml in C++ with QQuickView
//http://stackoverflow.com/questions/14092319/create-qml-element-in-c
QQuickView view;
//Background
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.setSource(QUrl("qrc:///game.qml"));
//Spaceshuttle
QQmlComponent component(view.engine(), QUrl("qrc:///shuttle.qml"));
QObject *shuttle = component.create();
//Components are only drawn if parent is somehow related to the root view
QQmlProperty::write(shuttle, "parent", QVariant::fromValue<QObject*>(view.rootObject()));
//some sample "Astroids" - ( wrong Image ;) )
QVector<QObject*> astroids(0);
for(int i = 0; i < 5; i++){
QQmlComponent fireballComponent(view.engine(), QUrl("qrc:///fireball.qml"));
astroids.append(fireballComponent.create());
QQmlProperty::write(astroids[i], "parent", QVariant::fromValue<QObject*>(view.rootObject()));
QQmlProperty::write(astroids[i], "x", i*50);
QQmlProperty::write(astroids[i], "y", i*50);
}
//QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership);
qDebug() << shuttle->property("id").toString();
Logger logger;
logger.setQObject(shuttle);
QObject::connect(shuttle, SIGNAL(xChanged()), &logger, SLOT(showCoordinates()));
view.show();
return app.exec();
}
示例4: textEdit
void tst_qquickfocusscope::textEdit()
{
QQuickView *view = new QQuickView;
view->setSource(testFileUrl("test5.qml"));
QQuickFocusScope *item0 = findItem<QQuickFocusScope>(view->rootObject(), QLatin1String("item0"));
QQuickTextEdit *item1 = findItem<QQuickTextEdit>(view->rootObject(), QLatin1String("item1"));
QQuickRectangle *item2 = findItem<QQuickRectangle>(view->rootObject(), QLatin1String("item2"));
QQuickTextEdit *item3 = findItem<QQuickTextEdit>(view->rootObject(), QLatin1String("item3"));
QVERIFY(item0 != 0);
QVERIFY(item1 != 0);
QVERIFY(item2 != 0);
QVERIFY(item3 != 0);
view->show();
view->requestActivate();
QTest::qWaitForWindowActive(view);
QTRY_VERIFY(view == qGuiApp->focusWindow());
QVERIFY(item0->hasActiveFocus() == true);
QVERIFY(item1->hasActiveFocus() == true);
QVERIFY(item2->hasActiveFocus() == false);
QVERIFY(item3->hasActiveFocus() == false);
QTest::keyClick(view, Qt::Key_Right);
QVERIFY(item0->hasActiveFocus() == true);
QVERIFY(item1->hasActiveFocus() == true);
QVERIFY(item2->hasActiveFocus() == false);
QVERIFY(item3->hasActiveFocus() == false);
QTest::keyClick(view, Qt::Key_Right);
QTest::keyClick(view, Qt::Key_Right);
QTest::keyClick(view, Qt::Key_Right);
QTest::keyClick(view, Qt::Key_Right);
QTest::keyClick(view, Qt::Key_Right);
QVERIFY(item0->hasActiveFocus() == true);
QVERIFY(item1->hasActiveFocus() == false);
QVERIFY(item2->hasActiveFocus() == true);
QVERIFY(item3->hasActiveFocus() == false);
QTest::keyClick(view, Qt::Key_Down);
QVERIFY(item0->hasActiveFocus() == false);
QVERIFY(item1->hasActiveFocus() == false);
QVERIFY(item2->hasActiveFocus() == false);
QVERIFY(item3->hasActiveFocus() == true);
delete view;
}
示例5: test_framerateAdvance
void tst_qquickspritesequence::test_framerateAdvance()
{
QQuickView *window = new QQuickView(0);
window->setSource(testFileUrl("advance.qml"));
window->show();
QVERIFY(QTest::qWaitForWindowExposed(window));
QVERIFY(window->rootObject());
QQuickSpriteSequence* sprite = window->rootObject()->findChild<QQuickSpriteSequence*>("sprite");
QVERIFY(sprite);
QTRY_COMPARE(sprite->currentSprite(), QLatin1String("secondState"));
delete window;
}
示例6: main
/*------------------------------------------------------------------------------
| main
+-----------------------------------------------------------------------------*/
int main(int argc, char* argv[])
{
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
QApplication a(argc, argv);
QStringList args = a.arguments();
const bool opengl = !args.contains("--no-opengl");
args.removeAll("--no-opengl");
if (opengl) {
qDebug("QML QtWebEngine...");
QQuickView* view = new QQuickView;
view->setSource(QUrl("qrc:/poc_main.qml"));
view->showFullScreen();
QObject* o = view->rootObject()->findChild<QObject*>("webEngineView");
o->setProperty("url", args.at(1));
}
else {
qDebug("Widget QtWebEngine...");
QWebEngineView* view = new QWebEngineView;
view->load(QUrl(args.at(1)));
view->show();
}
return a.exec();
}
示例7: QMainWindow
MsmWindow::MsmWindow(QWidget *parent) :
QMainWindow(parent)
{
// Prepare the view area
stackedWidget = new QStackedWidget(this);
setCentralWidget(stackedWidget);
QQuickView *view = new QQuickView();
menuView = QWidget::createWindowContainer(view, this);
menuView->setFocusPolicy(Qt::TabFocus);
view->setSource(QUrl("qrc:/qml/main.qml"));
stackedWidget->addWidget(menuView);
stackedWidget->setCurrentWidget(menuView);
moduleView = new ModuleView();
stackedWidget->addWidget(moduleView);
QQuickItem *rootObject = view->rootObject();
QQuickItem::connect(rootObject, SIGNAL(itemClicked(QString)),
this, SLOT(loadModule(QString)));
ModuleView::connect(moduleView, &ModuleView::closeRequest,
[=]() {
moduleView->resolveChanges();
moduleView->closeModules();
stackedWidget->setCurrentWidget(menuView);
});
init();
readPositionSettings();
}
示例8: test_move
void tst_qquickcustomaffector::test_move()
{
QQuickView* view = createView(testFileUrl("move.qml"), 600);
QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
ensureAnimTime(600, system->m_animation);
QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) {
if (d->t == -1)
continue; //Particle data unused
if (!d->stillAlive(system))
continue; //parameters no longer get set once you die
QVERIFY2(myFuzzyCompare(d->curX(system), 50.0), QByteArray::number(d->curX(system)));
QVERIFY2(myFuzzyCompare(d->curY(system), 50.0), QByteArray::number(d->curY(system)));
QVERIFY2(myFuzzyCompare(d->curVX(system), 50.0), QByteArray::number(d->curVX(system)));
QVERIFY2(myFuzzyCompare(d->curVY(system), 50.0), QByteArray::number(d->curVY(system)));
QVERIFY2(myFuzzyCompare(d->curAX(), 50.0), QByteArray::number(d->curAX()));
QVERIFY2(myFuzzyCompare(d->curAY(), 50.0), QByteArray::number(d->curAY()));
QCOMPARE(d->lifeSpan, 0.5f);
QCOMPARE(d->size, 32.f);
QCOMPARE(d->endSize, 32.f);
QVERIFY2(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)),
QString::fromLatin1("%1 <= %2 / 1000").arg(d->t).arg(system->timeInt).toUtf8());
}
delete view;
}
示例9: main
int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
qmlRegisterType<QVTKFrameBufferObjectItem>("VtkQuick", 1, 0, "VtkRenderWindow");
QQuickView view;
view.setSource(QUrl("qrc:///main.qml"));
QList<QVTKFrameBufferObjectItem*> vtkItems = view.rootObject()->findChildren<QVTKFrameBufferObjectItem*>();
// For demonstration: Add a cone to the scene of each QVTKFrameBufferObjectItem
Q_FOREACH(QVTKFrameBufferObjectItem *vtkItem, vtkItems)
{
vtkGenericOpenGLRenderWindow *r_win = vtkItem->GetRenderWindow();
vtkSmartPointer<vtkConeSource> cone = vtkSmartPointer<vtkConeSource>::New();
//cone->SetHeight(3.0);
//cone->SetRadius(1.0);
cone->SetResolution(100);
vtkSmartPointer<vtkPolyDataMapper> coneMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
coneMapper->SetInputConnection(cone->GetOutputPort());
vtkSmartPointer<vtkActor> coneActor = vtkSmartPointer<vtkActor>::New();
coneActor->SetMapper(coneMapper);
vtkSmartPointer<vtkRenderer> ren1 = vtkSmartPointer<vtkRenderer>::New();
ren1->AddActor(coneActor);
r_win->AddRenderer(ren1);
}
示例10: test_basic
void tst_qquickpointdirection::test_basic()
{
QQuickView* view = createView(testFileUrl("basic.qml"), 600);
QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
ensureAnimTime(600, system->m_animation);
QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) {
if (d->t == -1)
continue; //Particle data unused
QCOMPARE(d->x, 0.f);
QCOMPARE(d->y, 0.f);
QCOMPARE(d->vx, 100.f);
QCOMPARE(d->vy, 100.f);
QVERIFY(d->ax >= 0.f);
QVERIFY(d->ax <= 200.f);
QVERIFY(d->ay >= 0.f);
QVERIFY(d->ay <= 200.f);
QCOMPARE(d->lifeSpan, 0.5f);
QCOMPARE(d->size, 32.f);
QCOMPARE(d->endSize, 32.f);
QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
}
delete view;
}
示例11: main
int main(int argc, char **argv)
{
QGuiApplication *app = SailfishApp::application(argc, argv);
qmlRegisterType<Mainview>("harbour.monav", 1, 0, "Mainview");
qmlRegisterType<TapMenu>("harbour.monav", 1, 0, "TapMenu");
qmlRegisterType<MapPackages>("harbour.monav", 1, 0, "MapPackages");
qmlRegisterType<Bookmarks>("harbour.monav", 1, 0, "Bookmarks");
qmlRegisterType<PaintWidget>("harbour.monav", 1, 0, "PaintWidget");
qmlRegisterType<WorldMapChooser>("harbour.monav", 1, 0, "WorldMapChooser");
QQuickView *view = SailfishApp::createView();
view->setSource(SailfishApp::pathTo("qml/Main.qml"));
view->show();
view->setResizeMode(QQuickView::SizeRootObjectToView);
QObject *object = (QObject *) view->rootObject();
Mainview *mainview = object->findChild<Mainview *>("mainview");
mainview->init();
app->connect( app, SIGNAL(aboutToQuit()), MapData::instance(), SLOT(cleanup()) );
app->connect( app, SIGNAL(aboutToQuit()), RoutingLogic::instance(), SLOT(cleanup()) );
app->connect( app, SIGNAL(aboutToQuit()), Logger::instance(), SLOT(cleanup()) );
app->connect( app, SIGNAL(aboutToQuit()), mainview, SLOT(cleanup()) );
return app->exec();
}
示例12: testProperties
void tst_QQuickGraphicsInfo::testProperties()
{
QQuickView view;
view.setSource(QUrl("data/basic.qml"));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QSignalSpy spy(&view, SIGNAL(sceneGraphInitialized()));
spy.wait();
QObject* obj = view.rootObject();
QVERIFY(obj);
QSGRendererInterface *rif = view.rendererInterface();
const int expectedAPI = rif ? rif->graphicsApi() : QSGRendererInterface::Unknown;
QCOMPARE(obj->property("api").toInt(), expectedAPI);
#if QT_CONFIG(opengl)
if (expectedAPI == QSGRendererInterface::OpenGL) {
QCOMPARE(obj->property("shaderType").toInt(), int(QSGRendererInterface::GLSL));
QVERIFY(view.openglContext());
QSurfaceFormat format = view.openglContext()->format();
QCOMPARE(obj->property("majorVersion").toInt(), format.majorVersion());
QCOMPARE(obj->property("minorVersion").toInt(), format.minorVersion());
QCOMPARE(obj->property("profile").toInt(), static_cast<int>(format.profile()));
QCOMPARE(obj->property("renderableType").toInt(), static_cast<int>(format.renderableType()));
}
#endif
}
示例13: QDialog
void Fix8Log::aboutSlot()
{
QDialog *aboutDialog = new QDialog();
QVBoxLayout *aboutLayout = new QVBoxLayout(0);
QDialogButtonBox *dialogButtonBox = new QDialogButtonBox();
dialogButtonBox->addButton(QDialogButtonBox::Ok);
connect(dialogButtonBox,SIGNAL(clicked(QAbstractButton*)),
aboutDialog,SLOT(close()));
QQuickView *aboutView = new QQuickView(QUrl("qrc:qml/helpAbout.qml"));
QQuickItem *qmlObject = aboutView->rootObject();
qmlObject->setProperty("color",aboutDialog->palette().color(QPalette::Window));
qmlObject->setProperty("bgColor",aboutDialog->palette().color(QPalette::Window));
qmlObject->setProperty("version",QString::number(Globals::version));
aboutView->setResizeMode(QQuickView::SizeRootObjectToView);
QWidget *aboutWidget = QWidget::createWindowContainer(aboutView,0);
aboutWidget->setPalette(aboutDialog->palette());
aboutWidget->setAutoFillBackground(false);
aboutDialog->setLayout(aboutLayout);
aboutLayout->addWidget(aboutWidget,1);
aboutLayout->addWidget(dialogButtonBox,0);
aboutDialog->resize(500,400);
aboutDialog->setWindowTitle(GUI::Globals::appName);
aboutDialog->exec();
aboutDialog->deleteLater();
}
示例14: updateView
void MainWindow::updateView()
{
QSurfaceFormat format;
format.setDepthBufferSize(16);
format.setStencilBufferSize(8);
if (m_transparent)
format.setAlphaBufferSize(8);
if (m_checkboxMultiSample->isChecked())
format.setSamples(4);
State state = m_radioView->isChecked() ? UseWindow : UseWidget;
if (m_format == format && m_state == state)
return;
m_format = format;
m_state = state;
QString text = m_currentRootObject
? m_currentRootObject->property("currentText").toString()
: QStringLiteral("Hello Qt");
QUrl source("qrc:qquickviewcomparison/test.qml");
if (m_state == UseWindow) {
QQuickView *quickView = new QQuickView;
// m_transparent is not supported here since many systems have problems with semi-transparent child windows
quickView->setFormat(m_format);
quickView->setResizeMode(QQuickView::SizeRootObjectToView);
connect(quickView, &QQuickView::statusChanged, this, &MainWindow::onStatusChangedView);
connect(quickView, &QQuickView::sceneGraphError, this, &MainWindow::onSceneGraphError);
quickView->setSource(source);
m_currentRootObject = quickView->rootObject();
switchTo(QWidget::createWindowContainer(quickView));
} else if (m_state == UseWidget) {
QQuickWidget *quickWidget = new QQuickWidget;
if (m_transparent) {
quickWidget->setClearColor(Qt::transparent);
quickWidget->setAttribute(Qt::WA_TranslucentBackground);
}
quickWidget->setFormat(m_format);
quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
connect(quickWidget, &QQuickWidget::statusChanged, this, &MainWindow::onStatusChangedWidget);
connect(quickWidget, &QQuickWidget::sceneGraphError, this, &MainWindow::onSceneGraphError);
quickWidget->setSource(source);
m_currentRootObject = quickWidget->rootObject();
switchTo(quickWidget);
}
if (m_currentRootObject) {
m_currentRootObject->setProperty("currentText", text);
m_currentRootObject->setProperty("multisample", m_checkboxMultiSample->isChecked());
m_currentRootObject->setProperty("translucency", m_transparent);
}
m_overlayLabel->raise();
}
示例15: on_actionTextShadow_triggered
void HtmlEditor::on_actionTextShadow_triggered()
{
QQuickView* view = new QQuickView(QUrl::fromLocalFile(qmlFilePath("text_shadow.qml")));
view->setTitle(tr("Text Shadow"));
view->setColor(palette().window().color());
connect(view->rootObject(), SIGNAL(accepted(QString)), SLOT(formatTextShadow(QString)));
connect(view->engine(), SIGNAL(quit()), view, SLOT(close()));
view->show();
}