Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add QLine to QGridLayout

Tags:

c++

qt

qt4

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?

like image 864
Daniel Avatar asked Feb 19 '23 22:02

Daniel


1 Answers

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.

like image 148
Synxis Avatar answered Mar 02 '23 18:03

Synxis