简体   繁体   English

Qt串行通讯终端

[英]Qt serial communication terminal

I'm trying to modify Qt terminal example. 我正在尝试修改Qt终端示例。 I'm new to Qt and I have a problem with setCentralWidget(console); 我是Qt setCentralWidget(console); ,但setCentralWidget(console);有问题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 ? 有人可以帮助我更改此代码吗?

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: 首先,我们必须创建新的布局(例如gridlayout),然后将Widget添加到布局并通过Qwidget设置中央小部件,如下所示:

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM