Pilot Pilot - 3 months ago 35
C++ Question

Qt serial communication terminal

I'm trying to modify

Qt
terminal example. I'm new to
Qt
and I have a problem with
setCentralWidget(console);
Now the console is stretched to whole window. There is only a main toolbar, a status bar, a menu and I would like to add some buttons etc.

I know that I should use layers before setting central widget but I don't know how. I would like to put this console into small text area just to get info from serial. For sending commands buttons will be available.

Can some one help me with changing this code ?

Answer

I have found solution for my problem. It is very simple. First we have to create new layout for example gridlayout, then addWidget to layout and set central widget from Qwidget as below:

QGridLayout *layout = new QGridLayout;

layout->addWidget(ui->tabWidget, 0, 0, 1, 2);
layout->addWidget(ui->info, 1, 0, 1, 2);
layout->addWidget(console, 2, 0, 1, 2);

QWidget *window = new QWidget();
window->setLayout(layout);

setCentralWidget(window);