[SOLVED] Problem with resizeEvent in QQuickView with SizeRootObjectToView on
-
Hello all,
To show the problem, here is a minimalist program :
main.cpp
@
#include <QtGui/QGuiApplication>
#include <QQuickView>class View : public QQuickView
{
public:
View() {}
};int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
View qv;
qv.setSource(QUrl::fromLocalFile("qml/resize/main.qml"));
qv.setWidth(300);
qv.setHeight(500);
qv.setResizeMode(QQuickView::SizeRootObjectToView);
qv.show();
return app.exec();
}@
main.qml
@
import QtQuick 2.0Item {
id : root
Rectangle {
color: "red"
anchors.fill: parent
Text {
text: "Height : " + root.height + " and width : " + root.width
anchors.centerIn: parent
}
}
}
@Here, no problem. When i resize the windows, the red rectangle follows the window and the text show the size of the window.
Now i'm introcing the resizeEvent.
main.cpp
@
#include <QtGui/QGuiApplication>
#include <QQuickView>class View : public QQuickView
{
public:
View() {}
protected:
void resizeEvent(QResizeEvent * ev){}
};int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
View qv;
qv.setSource(QUrl::fromLocalFile("qml/resize/main.qml"));
qv.setWidth(300);
qv.setHeight(500);
qv.setResizeMode(QQuickView::SizeRootObjectToView);
qv.show();
return app.exec();
}@
main.qml
@
import QtQuick 2.0Item {
id : root
Rectangle {
color: "red"
anchors.fill: parent
Text {
text: "Height : " + root.height + " and width : " + root.width
anchors.centerIn: parent
}
}
}
@
Here, the problem is that the size of the rectangle doe'nt change with the resizing.I'm looking in the source code of Qt 5.1 in the funtion that i have overload (resizeEvent), there nothing in the functions.
So what ?
Have i miss something ?
Is thit a bug of Qt ?Thanks
-
Ok i find a solution. If i put :
@
QQuickItem* rootQml = rootObject();
rootQml->setProperty("width", ev->size().width());
rootQml->setProperty("height", ev->size().height());
@in the resizeEvent, it works.