0
votes

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
Since you have used QQuickWidget::SizeRootObjectToView have you provided width and height to root object in QML ? - astre
I have also attached the qml code - Vishwas
Are you sure window works? Since you draw only a rectanble maybe try only using this element if at least this works. - maxik
QQuickWidget does not support using windows as a root item. So you must replace it with Item or Rectangle or any component which instantiates Item. QQuickWidget is in fact an alternative to using QQuickView and QWidget::createWindowContainer(). And that QQuickView can only load components of type Item. - astre
Thanks, it worked as expected - Vishwas

1 Answers

0
votes

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.