添加清除按钮
This commit is contained in:
+10
-2
@@ -36,7 +36,7 @@ MainWidget::MainWidget(QWidget *parent)
|
||||
RecvArea->setPalette(pal);
|
||||
SendArea = new QTextEdit();
|
||||
RecvArea->setFont(QFont(tr("Microsoft YaHei UI"), 10));
|
||||
SendArea->setFont(QFont(tr("Microsoft YaHei UI"), 13));
|
||||
SendArea->setFont(QFont(tr("Microsoft YaHei UI Light"), 13));
|
||||
SendArea->installEventFilter(this);
|
||||
|
||||
//按钮
|
||||
@@ -44,8 +44,11 @@ MainWidget::MainWidget(QWidget *parent)
|
||||
SendButton = new QPushButton(tr("发送"));
|
||||
SendButton->setDisabled(true);
|
||||
SendButton->setToolTip(tr("Ctrl+Enter"));
|
||||
ClearButton = new QPushButton(tr("清除接收"));
|
||||
|
||||
connect(OpenButton, QPushButton::clicked, this, OpenSerial);
|
||||
connect(SendButton, QPushButton::clicked, this, SendContent);
|
||||
connect(ClearButton, QPushButton::clicked, this, ClearRecv);
|
||||
|
||||
//初始化布局
|
||||
layout = new QGridLayout(this);
|
||||
@@ -62,6 +65,7 @@ MainWidget::MainWidget(QWidget *parent)
|
||||
layout->addWidget(SendButton, 5, 2, Qt::AlignRight);
|
||||
layout->addWidget(RecvArea, 0, 2, 3, 1);
|
||||
layout->addWidget(SendArea, 3, 2, 2, 1);
|
||||
layout->addWidget(ClearButton, 0, 3);
|
||||
setLayout(layout);
|
||||
|
||||
//计时器 初始化
|
||||
@@ -91,7 +95,6 @@ MainWidget::MainWidget(QWidget *parent)
|
||||
connect(DatabitsBox, QComboBox::currentTextChanged, serialController, SerialController::getDatabits);
|
||||
connect(ParityBox, QComboBox::currentTextChanged, serialController, SerialController::getParity);
|
||||
connect(this, sendData, serialController, SerialController::writeData);
|
||||
connect(SendButton, QPushButton::clicked, this, SendContent);
|
||||
connect(serialController, SerialController::recvData, this, getRecv);
|
||||
}
|
||||
|
||||
@@ -181,6 +184,11 @@ void MainWidget::CloseSerial()
|
||||
emit requestClose();
|
||||
}
|
||||
|
||||
void MainWidget::ClearRecv()
|
||||
{
|
||||
RecvArea->clear();
|
||||
}
|
||||
|
||||
void MainWidget::SendContent()
|
||||
{
|
||||
QString content = SendArea->toPlainText();
|
||||
|
||||
+4
-4
@@ -42,6 +42,9 @@ public slots:
|
||||
void serialNotOpened(); //串口打开失败
|
||||
void serialClosed(); //串口关闭
|
||||
void getRecv(QByteArray recv); //串口接受数据
|
||||
void OpenSerial();
|
||||
void CloseSerial();
|
||||
void ClearRecv();
|
||||
|
||||
private:
|
||||
QComboBox *COMBox, *BaudrateBox, *StopbitsBox, *DatabitsBox, *ParityBox;
|
||||
@@ -49,14 +52,11 @@ private:
|
||||
QLabel *BaudrateLabel, *StopbitsLabel, *DatabitsLabel, *ParityLabel;
|
||||
QGridLayout *layout;
|
||||
QTextEdit *RecvArea, *SendArea;
|
||||
QPushButton *OpenButton, *SendButton;
|
||||
QPushButton *OpenButton, *SendButton, *ClearButton;
|
||||
QTimer *CheckTimer;
|
||||
SerialController *serialController;
|
||||
QThread SerialThr;
|
||||
|
||||
void OpenSerial();
|
||||
void CloseSerial();
|
||||
|
||||
};
|
||||
|
||||
#endif // MAINWIDGET_H
|
||||
|
||||
Reference in New Issue
Block a user