Results 1 to 17 of 17

Thread: Auto resize Widget to maximum avail. space

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Auto resize Widget to maximum avail. space

    Quote Originally Posted by wysota View Post
    First of all make sure the layout is setup properly. The form should have a layout set and inside that layout there should be your widget. The code you posted in the first post is a mess, so I didn't analyze it, but at a first glance it seems incorrect.
    Blame Trolltech not me. That code is auto generated.
    It is simply a qwidget with a Gridlayout within the qwtwidget is placed.
    Last edited by pospiech; 15th April 2008 at 10:01.

  2. #2
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    9
    Thanked 29 Times in 29 Posts

    Default Re: Auto resize Widget to maximum avail. space

    Perhaps you'd better post the .ui file, which is easier for humans to analyze. :-)
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Auto resize Widget to maximum avail. space

    Quote Originally Posted by pospiech View Post
    Blame Trolltech not me. That code is auto generated.
    It doesn't mean the form was correct. Could you attach the ui file?

  4. #4
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Auto resize Widget to maximum avail. space

    I have now created an independent example: (Sorry it does not use an .ui file)

    main.cpp
    Qt Code:
    1. #include <qt/qapplication.h>
    2. #include "MainWindow.h"
    3.  
    4. int main(int argc, char** argv)
    5. {
    6. QApplication app( argc, argv );
    7. MainWindow mainWindow;
    8. mainWindow.show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    MainWindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H_
    2. #define MAINWINDOW_H_
    3.  
    4. #include <QtGui/QApplication>
    5. #include <QtGui/QGridLayout>
    6. #include <QtGui/QMainWindow>
    7. #include <QtGui/QTextEdit>
    8. #include <QtGui/QWidget>
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13. public:
    14. QWidget *m_centralwidget;
    15. QWidget *gridLayout;
    16. QGridLayout *gridLayout1;
    17. QTextEdit *textEdit;
    18.  
    19. void setupUi(QMainWindow *MainWindow)
    20. {
    21. MainWindow->resize(500, 500);
    22. m_centralwidget = new QWidget(MainWindow);
    23.  
    24. QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    25. sizePolicy.setHorizontalStretch(0);
    26. sizePolicy.setVerticalStretch(0);
    27. m_centralwidget->setSizePolicy(sizePolicy);
    28.  
    29. gridLayout = new QWidget(m_centralwidget);
    30. gridLayout->setGeometry(QRect(50, 50, 300, 200));
    31. gridLayout->setSizePolicy(sizePolicy);
    32.  
    33. textEdit = new QTextEdit(gridLayout);
    34.  
    35. gridLayout1 = new QGridLayout(gridLayout);
    36. gridLayout1->setContentsMargins(0, 0, 0, 0);
    37. gridLayout1->addWidget(textEdit, 0, 0, 1, 1);
    38.  
    39. MainWindow->setCentralWidget(m_centralwidget);
    40.  
    41. QMetaObject::connectSlotsByName(MainWindow);
    42. } // setupUi
    43.  
    44. public:
    45. MainWindow(QWidget* parent = 0, Qt::WFlags flags = 0);
    46.  
    47. virtual ~MainWindow(){};
    48. //void resizeEvent(QResizeEvent * /* event */);
    49.  
    50. };
    51. #endif
    To copy to clipboard, switch view to plain text mode 

    MainWindow.cpp
    Qt Code:
    1. #include "MainWindow.h"
    2. //
    3. MainWindow::MainWindow(QWidget* parent /*= 0*/, Qt::WFlags flags /*= 0*/) : QMainWindow(parent, flags)
    4. {
    5. setupUi(this);
    6. }
    7.  
    8. //void MainWindow::resizeEvent(QResizeEvent * /* event */)
    9. //{
    10. // gridLayout->setGeometry(QRect(0, 0, this->width(), this->height()));
    11. //}
    To copy to clipboard, switch view to plain text mode 

    In this example nothing is resized if I resize the dialog.

    Matthias

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Auto resize Widget to maximum avail. space

    Why don't you post the UI file as requested? From what I see you are not applying a layout to the central widget, but I'd like to verify that using your UI file.

  6. #6
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Auto resize Widget to maximum avail. space

    Quote Originally Posted by wysota View Post
    Why don't you post the UI file as requested? From what I see you are not applying a layout to the central widget, but I'd like to verify that using your UI file.
    Here the UI file from which I took the resulting code for my example


    In my example I removed the statusbar and the menubar.
    Attached Files Attached Files
    Last edited by wysota; 15th April 2008 at 13:26. Reason: Changed inlined code into attachment

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Auto resize Widget to maximum avail. space

    Yes, I was right - you didn't apply a layout to the central widget itself. Instead you had a floating layout, hence the mess in code you provided. Didn't Designer warn you about a floating layout?

    Here is a corrected file.
    Attached Files Attached Files
    Last edited by wysota; 15th April 2008 at 14:17. Reason: Updated attachment

  8. #8
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Auto resize Widget to maximum avail. space

    Quote Originally Posted by wysota View Post
    Yes, I was right - you didn't apply a layout to the central widget itself. Instead you had a floating layout, hence the mess in code you provided. Didn't Designer warn you about a floating layout?
    What is a floating layout, and what exactly did I wrong? And no the designer never warned me. And I created the dialog as I created every dialog.

    Quote Originally Posted by wysota View Post
    Here is a corrected file.
    If I download and compare with my own one they have not changed. So I cannot see your corrections.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Auto resize Widget to maximum avail. space

    Quote Originally Posted by pospiech View Post
    What is a floating layout, and what exactly did I wrong?
    A floating layout is a layout without "parent" widget. Take your ui, open it, grab the layout with your mouse and try to move it. If it moves, it's floating.

    And I created the dialog as I created every dialog.
    If so, then you created every dialog incorrectly.

    If I download and compare with my own one they have not changed. So I cannot see your corrections.
    Hmm... sorry, must have forgotten to save the file. Try it again.

  10. #10
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Auto resize Widget to maximum avail. space

    Quote Originally Posted by wysota View Post
    A floating layout is a layout without "parent" widget. Take your ui, open it, grab the layout with your mouse and try to move it. If it moves, it's floating.
    Well, yes I can move every layout I have ever seen.

    So the question is how to have non floating layouts. What do I have to do in QtDesigner to do it correct?

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Auto resize Widget to maximum avail. space

    Click on the form itself and then on one of the layout buttons, like I did in my ui file.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.