I'm trying to develop a Tic Tac Toe game, in which i'll place a QGridLayout in the QMainWindow central widget. There, I intend on adding other widgets (board cells) and the lines separating the game cells.
Is this possible? I can't find any API to insert a QLine inside a QGridLayout..
If this is not possible, can I place the child widgets directly on the QMainWindow's central widget? If so, how?
Yes, you can make a Tic tac toe with QGridLayout in a container widget.
About lines: it's a convenience tool offered by Qt Designer, it does not exists directly. In fact, a line is a QFrame with some restyling:
QFrame* line = new QFrame();
line->setGeometry(QRect(/* ... */));
line->setFrameShape(QFrame::HLine); // Replace by VLine for vertical line
line->setFrameShadow(QFrame::Sunken);
You should give this frame a non null height (or width for vertical ones), for example 2 pixels. Lines in GUI can be only horizontal or vertical.
Note: when you don't know how a widget is done in Qt Designer (even the one included in Qt Creator), you should create a dialog containing only the desired widget, and then view the generated code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With