You are changing the geometry of your qml, not the Viewer. To do so:
- Geometry of the viewer can be changed using the QmlApplicationViewer object you would have created in your main function.
- But that object is in C++, so you need to expose a C++ function to qml, and call that function on click of this button.
Steps:
- Create a class and store the Application viewer object created in the main.cpp, inside this class for further calls.
- Expose a function in this class to qml. This function shall be able to modify the size using the application viewer object stored in the class.
- On click of qml rectangle, call this function.
main.cpp
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include "qdeclarativecontext.h"
#include "myclass.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QmlApplicationViewer *viewer = new QmlApplicationViewer();
MyClass myClassObject(viewer);
viewer->rootContext()->setContextProperty("myViewer", &myClassObject);
viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
viewer->setMainQmlFile(QLatin1String("qml/untitled/main.qml"));
viewer->showExpanded();
return app.exec();
}
myclass.h
#ifndef MYCLASS_H
#define MYCLASS_H
#include "qmlapplicationviewer.h"
class MyClass : public QObject
{
Q_OBJECT
public:
MyClass( QmlApplicationViewer * p ) { internalViewer = p ; }
Q_INVOKABLE void viewerResize(int x, int y, int length, int breadth)
{
internalViewer->setGeometry(internalViewer->x(),internalViewer->y(),length,breadth);
}
private:
QmlApplicationViewer *internalViewer;
};
#endif // MYCLASS_H
main.qml
import QtQuick 1.0
Rectangle {
width: 360
height: 360
Text {
text: "Hello World"
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked:
{
myViewer.viewerResize(0,0,110,110)
}
}
}