2 Attachment(s)
Window doesn't expand to show all elements of QHBoxLayout
I'm building a tic-tac-toe game.
In my main window, I've got a QHBoxLayout holding the board (UIBoard), and the settings (which now consist of a start and quit button). uiSettings uses a QGroupBox and a QVBoxLayout in order to hold the start and quit buttons.
Everything works, but when I start the program, I have to manually enlarge the window so that everything is shown -- not just the board.
Here's the code:
uiMain.hpp
Code:
#ifndef UIMAIN_HPP_
#define UIMAIN_HPP_
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QApplication>
#include "uiBoard.hpp"
#include "uiSettings.hpp"
namespace ttt {
Q_OBJECT
private:
UIBoard *uiboard_;
UISettings *uisettings_;
public:
UIMain();
};
}
#endif /*UIMAIN_HPP_*/
uiMain.cpp
Code:
#include "uiMain.hpp"
namespace ttt {
UIMain::UIMain() :
uiboard_( new UIBoard( 'X', true, this ) ),
uisettings_( new UISettings( this ) ),
uiboard_->setFixedSize( 300, 300 );
mainLayout_->addWidget( uiboard_ );
mainLayout_->addWidget( uisettings_ );
}
}
And finally, main.cpp
Code:
#include <iostream>
#include <QApplication>
#include "uiMain.hpp"
int main( int argc, char *argv[] ) {
ttt::UIMain game;
game.show();
return app.exec();
}
I've attached images showing what I see when I start the program, and what I see after I manually enlarge the window.
Any help would be greatly appreciated and I'd be happy to provide more information if it would help. :)
Re: Window doesn't expand to show all elements of QHBoxLayout
Add this line at the end of your constructor:
Code:
setFixedSize(sizeHint());
EDIT: or if you don't want a fixed size for the window, try:
Code:
resize(sizeHint());
Regards
1 Attachment(s)
Re: Window doesn't expand to show all elements of QHBoxLayout
Quote:
Originally Posted by
marcel
Add this line at the end of your constructor:
Code:
setFixedSize(sizeHint());
EDIT: or if you don't want a fixed size for the window, try:
Code:
resize(sizeHint());
Regards
When I try either of those in the UIMain() contructor, the board is still the only thing shown.
EDIT: I should mention that I'm able to resize so that some elements are only half-visible (like in the attached image). Maybe it's a clue to the problem? :confused:
Any other ideas (but thanks anyway :)) ?
Re: Window doesn't expand to show all elements of QHBoxLayout
It looks as if the widget does not have a layout set.
Could you try adding this as the last line in the constructor?
Code:
setLayout(mainLayout_);
If this alone does not work, see what happens if you subclass QDialog instead of QWidget.
Just replace QWidget with QDialog in the class declaration and in the constructor initialization list.
EDIT: it could be a problem with the fact that you're using "this" in the constructor initializer list. I am not sure if all compiler handle that well. Do you get any compile time warnings about that?
Regards
Re: Window doesn't expand to show all elements of QHBoxLayout
I don't know what to tell you, marcel. :(
I've inherited UIMain from QDialog and
Code:
setLayout( mainLayout_);
And it still defaults to just showing the board.
Maybe I could set the minimum size?
In any case, thanks for the continued help. :)
Re: Window doesn't expand to show all elements of QHBoxLayout
Weird.
Maybe if you can provide a compilable example it would be easier to spot the problem.
There's no need for minimum size. Setting the fixed size should have done it.
Regards
1 Attachment(s)
Re: Window doesn't expand to show all elements of QHBoxLayout
Quote:
Originally Posted by
marcel
Weird.
Maybe if you can provide a compilable example it would be easier to spot the problem.
There's no need for minimum size. Setting the fixed size should have done it.
Regards
Sorry marcel, but the game and the GUI are pretty entwined.
I'm releasing this under the GPL anyways (I'm just a hobbyst :)) so I'm happy to just post the sources.
The files that are problems here are uiSettings.[hpp, cpp] uiMain.[hpp, cpp] and main.cpp.
Re: Window doesn't expand to show all elements of QHBoxLayout
OK.
I have to download boost first.
Shouldn't take more than 30-45 minutes with the whole testing.
regards
Re: Window doesn't expand to show all elements of QHBoxLayout
Quote:
Originally Posted by
marcel
OK.
I have to download boost first.
Shouldn't take more than 30-45 minutes with the whole testing.
regards
Oy :eek:.
This is highly appreciated. :o
EDIT: Take all the time you need. I'm in no hurry.
Re: Window doesn't expand to show all elements of QHBoxLayout
OK.
There was a problem in UISettings. You did not have a layout for the holder widget( the container of the group box ).
Here's the fixed version:
Code:
//This file is part of QtTicTac.
//
// QTicTac is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// QTicTac is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright 2007 Jesse E. H-K
#include <QApplication>
#include "uiSettings.hpp"
namespace ttt {
UISettings
::UISettings( QWidget *parent
) : startb_
( new QPushButton( tr
( "&Start Game" ), settingsGroup_
) ),
quitb_
( new QPushButton( tr
( "&Quit" ), settingsGroup_
) ) {
vbox_->addWidget( startb_ );
vbox_->addWidget( quitb_ );
settingsGroup_->setLayout( vbox_ );
topLayout->addWidget( settingsGroup_ );
connect( quitb_, SIGNAL( clicked() ), qApp, SLOT( quit() ) );
}
}
I also set a fixed size for the dialog, since the table does have a fixed size.(i did not attach that )
Regards
Regards
Re: Window doesn't expand to show all elements of QHBoxLayout
That's fantastic! Thanks so much. :)
Re: Window doesn't expand to show all elements of QHBoxLayout