How to add QLine to QGridLayout

I am trying to develop a Tic Tac Toe game in which I put a QGridLayout in a central QMainWindow widget. There I intend to add other widgets (board cells) and lines separating game cells.

Is it possible? I can not find the API to insert QLine inside QGridLayout ..

If this is not possible, is it possible to place child widgets directly in the central QMainWindow widget? If so, how?

+4
source share
1 answer

Yes, you can do Tic tac toe with QGridLayout in container widgets.

About strings: this is a handy tool offered by Qt Designer, it does not exist directly. In fact, the string 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-empty height (or width for vertical), for example 2 pixels. Lines in the GUI can only be horizontal or vertical.

Note If you don’t know how the widget is made 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.

+6
source

All Articles