Adding QQuickWidget in QStackedWidget

柔情痞子 提交于 2019-12-12 03:37:51

问题


I am trying to add a qquickwidget along with some other qwidgets in qstackedwidget. But when I am trying to set the current widget to the qquickwidget nothing appears on the window. Is there something else that need to be done? I am also setting the view property of the qquickwidget to true

  QQuickWidget* mRoom = new QQuickWidget;
connect(mRoom, SIGNAL(statusChanged(QQuickWidget::Status)), this, SLOT(StatusChanged(QQuickWidget::Status)));
mRoom->setSource(QUrl::fromLocalFile("C:/Users/visjain/Desktop/main_vishwas.qml"));
mRoom->setResizeMode(QQuickWidget::SizeRootObjectToView);

QStackedWidget* mStack = new QStackedWidget(mparent);   
mStack->addWidget(mRoom);
mStack->setCurrentWidget(mRoom);
    mRoom->show();

qml code -

import QtQuick 2.5
import QtQuick.Window 2.2


Window {
visible: true
height: 1000
width: 1800
Rectangle{
    height: parent.height
    width: parent.width
    color: "red"
}
}

回答1:


Did you assign some QML file to the widget?

QQuickWidget *view = new QQuickWidget;
view->setSource(QUrl::fromLocalFile("myqmlfile.qml"));
view->show();

Some more source code might be helpful.

For some more detailed reference you might see this.


For putting a QWidget inside a QStackedWidget to the front you should use setCurrentIndex or setCurrentWidget. See this.



来源:https://stackoverflow.com/questions/38178712/adding-qquickwidget-in-qstackedwidget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!