Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Resizing Main Windows QML
QtWS25 Last Chance

Resizing Main Windows QML

Scheduled Pinned Locked Moved QML and Qt Quick
15 Posts 3 Posters 9.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bidochon
    wrote on last edited by
    #2

    Not sure I understand what you mean as resizing come for free with the Window element. You probably mean the resizing of the elements children of the window. If that what you meant, then using anchors in those elements will keep them proportional to the main window size.

    Bidochon

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jeanrl
      wrote on last edited by
      #3

      Is not that what I want is to resize the main window via code. You know the effect on the Windows Task Bar auto-hide it moves up, is what I want to do.

      1 Reply Last reply
      0
      • O Offline
        O Offline
        onek24
        wrote on last edited by
        #4

        I think i get what you want. I assume you are using the default MainWindow which is providet with a default widgets project.
        You basically just have to access this in the sourcefile of your MainWindow class:
        @this->setGeometry(const QRect &);@
        That way you can set the properties of the MainWindow, in that case width, height, x and y.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jeanrl
          wrote on last edited by
          #5

          Ok, I'll try, thanks.

          1 Reply Last reply
          0
          • O Offline
            O Offline
            onek24
            wrote on last edited by
            #6

            You're welcome. Tell me if it worked as expected.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jeanrl
              wrote on last edited by
              #7

              Not working out the implementation, could you give me more details if possible of course.

              1 Reply Last reply
              0
              • O Offline
                O Offline
                onek24
                wrote on last edited by
                #8

                From where do you want to rescale the Window? I'll provide you a function which rescales the Window into a given size:
                mainwindow.h
                @#ifndef MAINWINDOW_H
                #define MAINWINDOW_H

                #include <QMainWindow>

                namespace Ui {
                class MainWindow;
                }

                class MainWindow : public QMainWindow
                {
                Q_OBJECT

                public:
                    explicit MainWindow(QWidget *parent = 0);
                    ~MainWindow();
                    void rescaleWindow(int w, int h, int x=0, int y=0);
                
                private:
                    Ui::MainWindow *ui;
                

                };

                #endif // MAINWINDOW_H@
                mainwindow.cpp
                @#include "mainwindow.h"
                #include "ui_mainwindow.h"

                @MainWindow::MainWindow(QWidget *parent) :
                QMainWindow(parent),
                ui(new Ui::MainWindow)
                {
                ui->setupUi(this);
                }

                MainWindow::~MainWindow()
                {
                delete ui;
                }

                void MainWindow::rescaleWindow(int w, int h, int x, int y)
                {
                this->setGeometry(x, y, w, h);
                }@
                For forther information please read:
                "QWidget Geometry":http://qt-project.org/doc/qt-4.8/qwidget.html#geometry-prop

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jeanrl
                  wrote on last edited by
                  #9

                  I'm wanting to resize from QML, because I need to make a panel behave like a task manager to auto hide with animation, like this:

                  https://www.youtube.com/watch?v=m4futNHYPYI

                  Thanks for your attention.

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jeanrl
                    wrote on last edited by
                    #10

                    The video I posted the link is not mine, just picked up to show what I do.

                    1 Reply Last reply
                    0
                    • O Offline
                      O Offline
                      onek24
                      wrote on last edited by
                      #11

                      That means you just basically want to hide or unhide the application?

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        jeanrl
                        wrote on last edited by
                        #12

                        No, this is just an example for you to understand what I do.
                        I will create a panel in QML (a Rectangle) and will increase it or decrease in effect, something like what happens there in the video with the Task Bar. He will occupy the all window, so I need to increase or decrease the main window because when I reduce or increase the Rectangle it does inside the window only and is not what I want, I want the window to behave interia like him, understand?
                        If you have another solution to my problem can also

                        1 Reply Last reply
                        0
                        • O Offline
                          O Offline
                          onek24
                          wrote on last edited by
                          #13

                          bq. No, this is just an example for you to understand what I do.
                          I will create a panel in QML (a Rectangle) and will increase it or decrease in effect, something like what happens there in the video with the Task Bar.

                          bq. He will occupy the all window, so I need to increase or decrease the main window because when I reduce or increase the Rectangle it does inside the window only

                          Sorry if i might misunderstand you again but you want a Rectangle in your view which can reduce himself down or up, like in the video with the taskbar. And if it reduces itself down, it should scale the hole window or applicationwindow down, and if it scales up it should scale the hole window or applicationwindow up?

                          1 Reply Last reply
                          0
                          • J Offline
                            J Offline
                            jeanrl
                            wrote on last edited by
                            #14

                            Yes, more or less.

                            1 Reply Last reply
                            0
                            • O Offline
                              O Offline
                              onek24
                              wrote on last edited by
                              #15

                              Oh alright, so you basically want the part with the resizing, you already got your part done with the clicking?
                              For the resizing part you'll still need a resize function in your mainwindow class. Let's keep the old one from above. In QML you'll just resize your top-level-component.
                              If it is for example a Rectangle:
                              @Rectangle {
                              id: topLevelComp
                              // more code ..
                              }@
                              We'll give it an id. So if we have to resize the window, like for example with the onClicked: notification of a MouseArea, we just execute:
                              @onClicked: {
                              topLevelComp.width = 0
                              topLevelComp.height = 0
                              }@
                              The QML-resize part is mostly done. We now need a signal in our QML so we can call a Cpp function. For that we just declare it that way:
                              @Rectangle {
                              id: topLevelComp
                              signal resizeMyApplication()
                              // more code ..
                              }@
                              Now we can emit it in our onClicked notification:
                              @onClicked: {
                              topLevelComp.width = 0
                              topLevelComp.height = 0
                              resizeMyApplication()
                              }@
                              In Cpp we have got our QML-ApplicationViewer. For that case i'll use a QQuickView. We have to get the rootObject() of our Viewer:
                              @QQuickView *view = new QQuickView();
                              // ... some code
                              QObject *obj = (QObject *)view->rootObject();@
                              Now we just have to connect the signal with a given slot or signal, for example:
                              @connect(obj, SIGNAL(resizeMyApplication()), this, SLOT(resizeMe()));@
                              You'll need the resizeMe() slot for that. In the slot you just execute the void MainWindow::rescaleWindow(int w, int h, int x, int y) function. You can also put the resize directly into the slot:
                              @{
                              this->setGeometry(x, y, w, h);
                              }@

                              I hope that you'll understand what i mean and that i could help you. Feel free to ask for further informations or read this documentations:
                              "Qml Cpp Integration":http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-topic.html
                              "Interacting with QML Objects from Cpp ":http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-interactqmlfromcpp.html
                              "Thread on how to: invoke QML methods":http://qt-project.org/forums/viewthread/36154

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved