Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Wrong widget layout after maximized show
QtWS25 Last Chance

Wrong widget layout after maximized show

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.0k 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.
  • S Offline
    S Offline
    Scr3amer
    wrote on last edited by Scr3amer
    #1

    Hello everyone !

    I was doing some tests with a dummy Qt C++ desktop app (VS 2017 x64 Qt 5.12 & 5.9 Win 10)
    And I noticed a weird behaviour. I checked around on stackoverflow and here but I didn't find any answer yet.

    Here is the issue:

    I open a top level widget and maximize its size. (just a QPushButton)

    1_1546731923411_maximized no bug.png

    Then I close it by pressing the button which is connected to the hide slot.
    And then reopen the widget with another button calling its show slot and hope to see the same thing.

    But I end up with this wrong painting / layout with the button blocked in top left corner of the window.

    0_1546731923411_maximized bug.png

    Any idea on the origin of this behaviour ? What am I doing wrong ? I spent some time in the doc and even started scratching the top of Qt source but nothing weird so far.

    Thank you in advance for any help !
    And happy new year by the way ^^ !
    Cheers,

    NB: I feel it is connected with the fact that widgets don't remember their size when we hide and show them again. They just remember if they are maximized or not and their position in the latter case.

    NB2: Source code

    ---------------------main.cpp

    #include "testapqtgui.h"
    #include <QtWidgets/QApplication>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    testapqtgui w;
    w.show();
    return a.exec();
    }

    --------------testapqtgui.h

    #pragma once

    #include <QtWidgets/QMainWindow>

    class testapqtgui : public QMainWindow
    {
    Q_OBJECT

    public:
    testapqtgui(QWidget *parent = Q_NULLPTR);

    private:
    };

    ------------------testapqtgui.cpp

    #include "testapqtgui.h"

    #include <QPushButton>

    testapqtgui::testapqtgui(QWidget *parent)
    : QMainWindow(parent)
    {
    QPushButton *const button = new QPushButton(tr("Click me !"));
    setCentralWidget(button);

    QPushButton *popupWidget = new QPushButton(tr("Close"));
    
    connect(button, &QPushButton::clicked, popupWidget, &QWidget::show);
    connect(popupWidget, &QPushButton::clicked, popupWidget, &QWidget::hide);
    

    }

    ODБOïO Pl45m4P 2 Replies Last reply
    0
    • S Offline
      S Offline
      Scr3amer
      wrote on last edited by Scr3amer
      #3

      Hi @LeLev !

      Oh wow nice finding ! Thanks for the information. I'll go with this workaround.
      I will dig in the source of Qt to see if there is not an improvement to be made here.

      I will leave the topic open a little bit more to see if someone has a complete answer, otherwise I will close it in 24-48 hrs as resolved.

      Thanks again !

      EDIT: I found something new. You don't even need to resize the window. You just need to set the resized flag to solve the issue.
      popupWidget->setAttribute(Qt::WA_Resized);

      EDIT2: Ok now I think I have the proper final solution for my use case:
      popupWidget->adjustSize();

      It will compute the right size, do a resize therefore set the flag. So you have no visual issue and you have a proper initial size.

      Thank you very much @LeLev ! You gave me the initial bit of information I needed to fix my issue :D ! Have a great day !

      1 Reply Last reply
      4
      • S Scr3amer

        Hello everyone !

        I was doing some tests with a dummy Qt C++ desktop app (VS 2017 x64 Qt 5.12 & 5.9 Win 10)
        And I noticed a weird behaviour. I checked around on stackoverflow and here but I didn't find any answer yet.

        Here is the issue:

        I open a top level widget and maximize its size. (just a QPushButton)

        1_1546731923411_maximized no bug.png

        Then I close it by pressing the button which is connected to the hide slot.
        And then reopen the widget with another button calling its show slot and hope to see the same thing.

        But I end up with this wrong painting / layout with the button blocked in top left corner of the window.

        0_1546731923411_maximized bug.png

        Any idea on the origin of this behaviour ? What am I doing wrong ? I spent some time in the doc and even started scratching the top of Qt source but nothing weird so far.

        Thank you in advance for any help !
        And happy new year by the way ^^ !
        Cheers,

        NB: I feel it is connected with the fact that widgets don't remember their size when we hide and show them again. They just remember if they are maximized or not and their position in the latter case.

        NB2: Source code

        ---------------------main.cpp

        #include "testapqtgui.h"
        #include <QtWidgets/QApplication>

        int main(int argc, char *argv[])
        {
        QApplication a(argc, argv);
        testapqtgui w;
        w.show();
        return a.exec();
        }

        --------------testapqtgui.h

        #pragma once

        #include <QtWidgets/QMainWindow>

        class testapqtgui : public QMainWindow
        {
        Q_OBJECT

        public:
        testapqtgui(QWidget *parent = Q_NULLPTR);

        private:
        };

        ------------------testapqtgui.cpp

        #include "testapqtgui.h"

        #include <QPushButton>

        testapqtgui::testapqtgui(QWidget *parent)
        : QMainWindow(parent)
        {
        QPushButton *const button = new QPushButton(tr("Click me !"));
        setCentralWidget(button);

        QPushButton *popupWidget = new QPushButton(tr("Close"));
        
        connect(button, &QPushButton::clicked, popupWidget, &QWidget::show);
        connect(popupWidget, &QPushButton::clicked, popupWidget, &QWidget::hide);
        

        }

        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #2

        @Scr3amer hi,
        i have the same behavior, i don't know how it wots internally but giving a size to popupWidget solved the issue

        popupWidget->resize(400,400);
        
        1 Reply Last reply
        3
        • S Offline
          S Offline
          Scr3amer
          wrote on last edited by Scr3amer
          #3

          Hi @LeLev !

          Oh wow nice finding ! Thanks for the information. I'll go with this workaround.
          I will dig in the source of Qt to see if there is not an improvement to be made here.

          I will leave the topic open a little bit more to see if someone has a complete answer, otherwise I will close it in 24-48 hrs as resolved.

          Thanks again !

          EDIT: I found something new. You don't even need to resize the window. You just need to set the resized flag to solve the issue.
          popupWidget->setAttribute(Qt::WA_Resized);

          EDIT2: Ok now I think I have the proper final solution for my use case:
          popupWidget->adjustSize();

          It will compute the right size, do a resize therefore set the flag. So you have no visual issue and you have a proper initial size.

          Thank you very much @LeLev ! You gave me the initial bit of information I needed to fix my issue :D ! Have a great day !

          1 Reply Last reply
          4
          • S Scr3amer

            Hello everyone !

            I was doing some tests with a dummy Qt C++ desktop app (VS 2017 x64 Qt 5.12 & 5.9 Win 10)
            And I noticed a weird behaviour. I checked around on stackoverflow and here but I didn't find any answer yet.

            Here is the issue:

            I open a top level widget and maximize its size. (just a QPushButton)

            1_1546731923411_maximized no bug.png

            Then I close it by pressing the button which is connected to the hide slot.
            And then reopen the widget with another button calling its show slot and hope to see the same thing.

            But I end up with this wrong painting / layout with the button blocked in top left corner of the window.

            0_1546731923411_maximized bug.png

            Any idea on the origin of this behaviour ? What am I doing wrong ? I spent some time in the doc and even started scratching the top of Qt source but nothing weird so far.

            Thank you in advance for any help !
            And happy new year by the way ^^ !
            Cheers,

            NB: I feel it is connected with the fact that widgets don't remember their size when we hide and show them again. They just remember if they are maximized or not and their position in the latter case.

            NB2: Source code

            ---------------------main.cpp

            #include "testapqtgui.h"
            #include <QtWidgets/QApplication>

            int main(int argc, char *argv[])
            {
            QApplication a(argc, argv);
            testapqtgui w;
            w.show();
            return a.exec();
            }

            --------------testapqtgui.h

            #pragma once

            #include <QtWidgets/QMainWindow>

            class testapqtgui : public QMainWindow
            {
            Q_OBJECT

            public:
            testapqtgui(QWidget *parent = Q_NULLPTR);

            private:
            };

            ------------------testapqtgui.cpp

            #include "testapqtgui.h"

            #include <QPushButton>

            testapqtgui::testapqtgui(QWidget *parent)
            : QMainWindow(parent)
            {
            QPushButton *const button = new QPushButton(tr("Click me !"));
            setCentralWidget(button);

            QPushButton *popupWidget = new QPushButton(tr("Close"));
            
            connect(button, &QPushButton::clicked, popupWidget, &QWidget::show);
            connect(popupWidget, &QPushButton::clicked, popupWidget, &QWidget::hide);
            

            }

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #4

            @Scr3amer

            I have the same problem with my project...
            In my opinion they mixed up "Maximize" and "Minimize".
            If you put one PushButton and something different like a Label inside a layout box and set the PushButtons size policy to max, the LABEL size increases while Pushbutton itself gets smaller and vice versa.
            If you use min, the objects have the same weird behavior...
            I really think they mixed them up.


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            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