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
#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_*/
#ifndef UIMAIN_HPP_
#define UIMAIN_HPP_
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QApplication>
#include "uiBoard.hpp"
#include "uiSettings.hpp"
namespace ttt {
class UIMain : public QWidget {
Q_OBJECT
private:
UIBoard *uiboard_;
UISettings *uisettings_;
QHBoxLayout *mainLayout_;
public:
UIMain();
};
}
#endif /*UIMAIN_HPP_*/
To copy to clipboard, switch view to plain text mode
uiMain.cpp
#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_ );
}
}
#include "uiMain.hpp"
namespace ttt {
UIMain::UIMain() :
QWidget(),
uiboard_( new UIBoard( 'X', true, this ) ),
uisettings_( new UISettings( this ) ),
mainLayout_( new QHBoxLayout( this ) ) {
uiboard_->setFixedSize( 300, 300 );
mainLayout_->addWidget( uiboard_ );
mainLayout_->addWidget( uisettings_ );
}
}
To copy to clipboard, switch view to plain text mode
And finally, main.cpp
#include <iostream>
#include <QApplication>
#include "uiMain.hpp"
int main( int argc, char *argv[] ) {
ttt::UIMain game;
game.show();
return app.exec();
}
#include <iostream>
#include <QApplication>
#include "uiMain.hpp"
int main( int argc, char *argv[] ) {
QApplication app( argc, argv );
ttt::UIMain game;
game.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
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.
Bookmarks