Results 1 to 8 of 8

Thread: Automatic Resizing

  1. #1
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Question Automatic Resizing

    In my Qt 3.3 project, I have noticed when I resize my window nothing shrinks or stretches with it. The pieces either disappear or a lot of empty space is added based on if I shrink or stretch the GUI. The GUIs I have made in Qt 4.2 always resize when the window resizes. Upon converting a Qt 4 GUI to Qt 3, the GUI doesn't resize with the resized window. I never worried about reimplementing the resizeEvent for my class in Qt 4 and everything worked, so why does the Qt 3 GUI not resize? Thanks for all your help!

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Automatic Resizing

    It has nothing to do with the resize event. Simply use layouts for your widgets and it will all work.

  3. #3
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Automatic Resizing

    Sorry...here is the code I have started with. I have some more to add but want to get something working.

    Qt Code:
    1. bool MainWindow::createGUI
    2. {
    3. QFrame *mainFrame = new QFrame( this );
    4. QWidget *layoutWidget = new QWidget( mainFrame );
    5. QVBoxLayout *mainLayout = new QVBoxLayout( layoutWidget );
    6.  
    7. mpTopLabal = new QLabel( tr( "Hello" ), layoutWidget );
    8. mpTopLabel->setAlignment( Qt::AlignRight );
    9. mpTopLabel->setMaximumHeight( 30 );
    10. mainLayout->addWidget( mpTopLabel );
    11.  
    12. QSplitter *mainSplitter = new QSPlitter( QSplitter::Horizontal, layoutWidget );
    13. QFrame *constraintFrame = new QFrame( mainSplitter );
    14. QWidget *constraintWidget = new QWidget( constraintFrame );
    15. QVBoxLayout *constraintLayout = new QVBoxLayout( constraintWidget );
    16.  
    17. mpDisplayBox = new QVGroupBox( tr( "Display Constraints:" ), constraintWidget );
    18. createDisplayBox( );
    19. constraintLayout->addWidget( mpDisplayBox );
    20.  
    21. // I will work with the table later but I want to add the 2nd item to the splitter.
    22. // A splitter with just one item seems pretty useless and I will have a 2nd item
    23. // once the left side is done.
    24. QFrame *tableFrame = new QFrame( mainSplitter );
    25. mainLayout->addWidget( mainSplitter );
    26. mpBottomLabel = new QLabel( tr( "Bye" ), layoutWidget );
    27. mpBottomLabel->setAlignment( Qt::AlignLeft );
    28. mpBottomLabel->setMaximumHeight( 30 );
    29. mainLayout->addWidget( mpBottomLabel );
    30.  
    31. setCentralWidget( mainFrame );
    32.  
    33. return true;
    34. }
    To copy to clipboard, switch view to plain text mode 

    and....

    Qt Code:
    1. bool MainWindow::createDisplayBox( )
    2. {
    3. QWidget *dummyWidget = new QWidget( mpDisplayBox );
    4. QGridLayout *displayLayout = new QGridLayout( dummyWidget );
    5.  
    6. QLabel *collectorsLabel = new QLabel( tr( "Collectors: ), dummyWidget );
    7. QLabel *minLabal = new QLabel( tr( "Min:" ), dummyWidget );
    8. QLabel *maxLabel = new QLabel( tr( "Max:" ), dummyWidget );
    9. mpCollectorsBox = new QComboBox( dummyWidget );
    10. mpMinLineEdit = new QLineEdit( dummyWidget );
    11. mpMaxLineEdit = new QLineEdit( dummyWidget );
    12.  
    13. mpCollectorsBox->insertItem( tr( "1" ) );
    14. mpCollectorsBox->insertItem( tr( "2" ) );
    15. mpCollectorsBox->insertItem( tr( "3" ) );
    16. mpCollectorsBox->insertItem( tr( "4" ) );
    17. mpCollectorsBox->insertItem( tr( "5" ) );
    18.  
    19. displayLayout->addMultiCellWidget( collectorsLabel, 0, 0, 0, 1 );
    20. displayLayout->addMutliCellWidget( mpCollectorsBox, 0, 0, 3, 3 );
    21. displayLayout->addMutliCellWidget( minLabel, 1, 1, 0, 0 );
    22. displayLayout->addMutliCellWidget( mpMinLineEdit, 1, 1, 1, 3 );
    23. displayLayout->addMutliCellWidget( maxLabel, 2, 2, 0, 0 );
    24. displayLayout->addMutliCellWidget( mpMaxLineEdit, 2, 2, 1, 3 );
    25.  
    26. displayLayout->setColStretch( 0, 0 );
    27. displayLayout->setColStretch( 1, 5 );
    28. displayLayout->setColStretch( 2, 5 );
    29.  
    30. return true;
    31. }
    To copy to clipboard, switch view to plain text mode 

    So you can see I am using layouts. Sorry if I have a typo, the machine I do my developing on is not connected to the internet so I have to retype my code to post it. I plan to add my QGroupBoxes in the constraintLayout but want to get one working first and trhis resizing issue is bugging me. Thanks again for your help!

  4. #4
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Automatic Resizing

    Anybody have any ideas why the layouts aren't allowing me to automatically resize? Thanks!

  5. #5
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Automatic Resizing

    I have messed around with the QSizePolicy of the widgets and the resizeMode of the layouts but cannot seem to get these to help me out any. The widgets still do not automatically resize even though they are inside the layouts. Thanks again for your help!

  6. #6
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Automatic Resizing

    I've edited your method slightly:

    Qt Code:
    1. bool MainWindow::createGUI
    2. {
    3. QFrame *mainFrame = new QFrame( this );
    4. // QWidget *layoutWidget = new QWidget( mainFrame );
    5. QVBoxLayout *mainLayout = new QVBoxLayout( /* layoutWidget */ mainFrame );
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 

    Does it work now?
    Save yourself some pain. Learn C++ before learning Qt.

  7. The following user says thank you to Chicken Blood Machine for this useful post:

    ToddAtWSU (22nd January 2007)

  8. #7
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Automatic Resizing

    Thanks that seems to fix it. Why would having that middle widget hurt things? Thanks for your help!

  9. #8
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Automatic Resizing

    The middle widget doesn't hurt things, it's just unnecessary.

    What hurt things, was the fact that you did not apply a layout to the top level widget.
    Save yourself some pain. Learn C++ before learning Qt.

Similar Threads

  1. form not auto resizing
    By quickNitin in forum Newbie
    Replies: 5
    Last Post: 7th June 2007, 10:00
  2. QTabWidget - problem with resizing
    By moowy in forum Qt Programming
    Replies: 5
    Last Post: 14th September 2006, 14:06
  3. Problem with resizing dialog
    By Seema Rao in forum Qt Programming
    Replies: 8
    Last Post: 5th May 2006, 17:27
  4. How to capture resizing of QTreeWidget columns?
    By simk in forum Qt Programming
    Replies: 2
    Last Post: 27th April 2006, 06:10
  5. Prevent from resizing a QMainWindow
    By Flier in forum Qt Tools
    Replies: 5
    Last Post: 14th April 2006, 17:11

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.