问题
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