With one exception (see below) I carefully copied this example, but the automatic resizing does not work (the rest works 100%). Here is my code:
QDeclarativeView * pCanvas = new QDeclarativeView;
setCentralWidget(pCanvas);
QDeclarativeEngine *engine = pCanvas->engine();
QDeclarativeComponent component
(engine,
QUrl::fromLocalFile("test.qml"));
pObject = component.create();
pCanvas->scene()->addItem(qobject_cast<QDeclarativeItem*>(pObject));
pCanvas->scene()->setBackgroundBrush(Qt::yellow);
pCanvas->setResizeMode(QDeclarativeView::SizeRootObjectToView);
}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
QDeclarativeView * pCanvas = new QDeclarativeView;
setCentralWidget(pCanvas);
QDeclarativeEngine *engine = pCanvas->engine();
QDeclarativeComponent component(engine, QUrl::fromLocalFile("test.qml"));
pObject = component.create();
pCanvas->setScene(new QGraphicsScene);
pCanvas->scene()->addItem(qobject_cast<QDeclarativeItem*>(pObject));
pCanvas->scene()->setBackgroundBrush(Qt::yellow);
pCanvas->setResizeMode(QDeclarativeView::SizeRootObjectToView);
}
To copy to clipboard, switch view to plain text mode
The part I missed out is the User Interface initialization and setup:
ui(new Ui::MainWindow)
and
ui->setupUi(this);
ui(new Ui::MainWindow)
and
ui->setupUi(this);
To copy to clipboard, switch view to plain text mode
As a newbie, I cannot see what difference this could make. Any hints gratefully received.
Bookmarks