Hi,

I have a qml file which contains a Rectangle Element as the root item. I want this rectangle item to be displayed as the mainwindows central widget and this Rectangle Element should be resized according to the mainwindow. So i did like this,

Qt Code:
  1. MainWindow::MainWindow(QWidget *parent)
  2. : QMainWindow(parent), ui(new Ui::MainWindow)
  3. {
  4. ui->setupUi(this);
  5.  
  6. QDeclarativeView *view = new QDeclarativeView;
  7. setCentralWidget(view);
  8.  
  9. QDeclarativeEngine *engine = view->engine();
  10.  
  11. QDeclarativeComponent component(engine, QUrl::fromLocalFile("qml_files/screen.qml"));
  12. object = component.create();
  13. view->setScene(new QGraphicsScene);
  14. view->scene()->addItem(qobject_cast<QDeclarativeItem*>(object));
  15. }
  16.  
  17. void MainWindow::resizeEvent(QResizeEvent *)
  18. {
  19. object->setProperty("width", width());
  20. object->setProperty("height", height());
  21. }
  22.  
  23.  
  24. screen.qml
  25.  
  26. Rectangle {
  27. id: window
  28.  
  29. width: 480; height: 360
  30. color: "#282828"
  31. }
To copy to clipboard, switch view to plain text mode 
which uses QDeclarativeView, QGraphicsScene, QDeclarativeComponent and QDeclarativeItem, which seems to work. Am i doing it right or a much simpler solution exist