Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

Changing width and height

$
0
0
Hello, i just started learning QML and i have a really simple problem: i want to change the size of my main window with my cpp code and i just does not work :( Here is a little example: import QtQuick 2.0   Rectangle {     width: 360     height: 360     color: "white"       Rectangle {         x: 200         y: 203         width: 96         height: 92         color: "yellow"         objectName: "objectName"     } } #include <QtGui/QGuiApplication> #include "qtquick2applicationviewer.h" #include "qqmlengine.h" #include "qqmlcomponent.h" #include "qquickitem.h"   int main(int argc, char *argv[]) {     QGuiApplication app(argc, argv);       QtQuick2ApplicationViewer viewer;     viewer.setMainQmlFile(QStringLiteral("qml/Test/main.qml"));       QQuickItem *object = viewer.rootObject();     QQuickItem *rect = object->findChild<QQuickItem*>("objectName");       object->setProperty("width", 20);     object->setProperty("height", 20);     object->setProperty("color", "black");       rect->setProperty("width", 10);     rect->setProperty("height", 10);       viewer.showExpanded();       return app.exec(); } Those two lines just don’t do anything: object->setProperty("width", 20); object->setProperty("height", 20); Changing the color of object works. Changing width and height of rect also works. The only thing that does not work is changing the size of object and i cant figure out why. Changing width and height in my QML code also works. Can anyone please tell me how i can change this size?? Thanks! :)

Viewing all articles
Browse latest Browse all 4972