0

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"
}
}
Vishwas
  • 506
  • 1
  • 5
  • 20
  • Since you have used `QQuickWidget::SizeRootObjectToView` have you provided `width` and `height` to root object in QML ? – astre Jul 04 '16 at 07:39
  • I have also attached the qml code – Vishwas Jul 04 '16 at 07:45
  • 1
    Are you sure window works? Since you draw only a rectanble maybe try only using this element if at least this works. – maxik Jul 04 '16 at 07:48
  • 1
    `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 Jul 04 '16 at 08:06
  • Thanks, it worked as expected – Vishwas Jul 04 '16 at 08:58

1 Answers1

0

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.

maxik
  • 1,053
  • 13
  • 34
  • Yes, maxik I have done all this, Also I am only setting view->show() when I want it to be the current widget in my qstackedwidget – Vishwas Jul 04 '16 at 07:19