PDA

View Full Version : Automatic Resizing



ToddAtWSU
16th January 2007, 13:48
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!

e8johan
16th January 2007, 14:16
It has nothing to do with the resize event. Simply use layouts for your widgets and it will all work.

ToddAtWSU
16th January 2007, 14:38
Sorry...here is the code I have started with. I have some more to add but want to get something working.



bool MainWindow::createGUI
{
QFrame *mainFrame = new QFrame( this );
QWidget *layoutWidget = new QWidget( mainFrame );
QVBoxLayout *mainLayout = new QVBoxLayout( layoutWidget );

mpTopLabal = new QLabel( tr( "Hello" ), layoutWidget );
mpTopLabel->setAlignment( Qt::AlignRight );
mpTopLabel->setMaximumHeight( 30 );
mainLayout->addWidget( mpTopLabel );

QSplitter *mainSplitter = new QSPlitter( QSplitter::Horizontal, layoutWidget );
QFrame *constraintFrame = new QFrame( mainSplitter );
QWidget *constraintWidget = new QWidget( constraintFrame );
QVBoxLayout *constraintLayout = new QVBoxLayout( constraintWidget );

mpDisplayBox = new QVGroupBox( tr( "Display Constraints:" ), constraintWidget );
createDisplayBox( );
constraintLayout->addWidget( mpDisplayBox );

// I will work with the table later but I want to add the 2nd item to the splitter.
// A splitter with just one item seems pretty useless and I will have a 2nd item
// once the left side is done.
QFrame *tableFrame = new QFrame( mainSplitter );
mainLayout->addWidget( mainSplitter );
mpBottomLabel = new QLabel( tr( "Bye" ), layoutWidget );
mpBottomLabel->setAlignment( Qt::AlignLeft );
mpBottomLabel->setMaximumHeight( 30 );
mainLayout->addWidget( mpBottomLabel );

setCentralWidget( mainFrame );

return true;
}


and....



bool MainWindow::createDisplayBox( )
{
QWidget *dummyWidget = new QWidget( mpDisplayBox );
QGridLayout *displayLayout = new QGridLayout( dummyWidget );

QLabel *collectorsLabel = new QLabel( tr( "Collectors: ), dummyWidget );
QLabel *minLabal = new QLabel( tr( "Min:" ), dummyWidget );
QLabel *maxLabel = new QLabel( tr( "Max:" ), dummyWidget );
mpCollectorsBox = new QComboBox( dummyWidget );
mpMinLineEdit = new QLineEdit( dummyWidget );
mpMaxLineEdit = new QLineEdit( dummyWidget );

mpCollectorsBox->insertItem( tr( "1" ) );
mpCollectorsBox->insertItem( tr( "2" ) );
mpCollectorsBox->insertItem( tr( "3" ) );
mpCollectorsBox->insertItem( tr( "4" ) );
mpCollectorsBox->insertItem( tr( "5" ) );

displayLayout->addMultiCellWidget( collectorsLabel, 0, 0, 0, 1 );
displayLayout->addMutliCellWidget( mpCollectorsBox, 0, 0, 3, 3 );
displayLayout->addMutliCellWidget( minLabel, 1, 1, 0, 0 );
displayLayout->addMutliCellWidget( mpMinLineEdit, 1, 1, 1, 3 );
displayLayout->addMutliCellWidget( maxLabel, 2, 2, 0, 0 );
displayLayout->addMutliCellWidget( mpMaxLineEdit, 2, 2, 1, 3 );

displayLayout->setColStretch( 0, 0 );
displayLayout->setColStretch( 1, 5 );
displayLayout->setColStretch( 2, 5 );

return true;
}


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!

ToddAtWSU
18th January 2007, 13:19
Anybody have any ideas why the layouts aren't allowing me to automatically resize? Thanks!

ToddAtWSU
19th January 2007, 14:40
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!

Chicken Blood Machine
22nd January 2007, 01:28
I've edited your method slightly:



bool MainWindow::createGUI
{
QFrame *mainFrame = new QFrame( this );
// QWidget *layoutWidget = new QWidget( mainFrame );
QVBoxLayout *mainLayout = new QVBoxLayout( /* layoutWidget */ mainFrame );
...
}


Does it work now?

ToddAtWSU
22nd January 2007, 14:09
Thanks that seems to fix it. Why would having that middle widget hurt things? Thanks for your help!

Chicken Blood Machine
22nd January 2007, 18:41
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.