Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9173379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:34:34+00:00 2026-06-17T16:34:34+00:00

I have Qt Creator 2.6.1. I created simple Qt Qucik 2.0 project from project

  • 0

I have Qt Creator 2.6.1.
I created simple Qt Qucik 2.0 project from project templates and changed main.qml file on this:

import QtQuick 2.0

Rectangle {
    width: 360
    height: 360

    color: "red"

    MouseArea {
        anchors.fill: parent
        onClicked: parent.height = 180
    }
}

If i will click on rectangle it should be reduced in half. And it is occured, but window is not reduced.

What is a best solution, if i want that main window must repeat geometry of main qml rectangle?

UPDATE. One solution was found. See Amit Tomar answer. But is exist more easier solution, for example, using QtQuick 5.0: Qt Quick Window QML Types ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:34:35+00:00Added an answer on June 17, 2026 at 4:34 pm

    You are changing the geometry of your qml, not the Viewer. To do so:

    1. Geometry of the viewer can be changed using the QmlApplicationViewer object you would have created in your main function.
    2. 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:

    1. Create a class and store the Application viewer object created in the main.cpp, inside this class for further calls.
    2. 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.
    3. 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)
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple project created in Qt Creator (installed using Qt SDK 1.1.4).
I have a simple module created with the Magento Module Creator with a couple
I have created a QDialog based app using Qt Creator and all is well
I have created an MDI application (using Qt 4.6) in Qt Creator and added
Have a painfully simple blog Post creator, and I'm trying to check if the
I have a DLL made in C#, this DLL contains some clases like Creator.
I have created a simple SyndicationFeed with many SyndicationItems. Each SyndicationItem has HtmlContent. The
I have created an XML file called temp.gpx in internal storage, and now I
Qt Creator give the possibility to attach some resource to the project. I created
I have created a windows service which allows communications via namedpipes. This code worked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.