Qt中的QCheckBox与Matlab

134 篇文章 ¥59.90 ¥99.00
本文介绍如何在Qt应用程序中使用QCheckBox控件,并与Matlab进行交互。通过示例代码展示QCheckBox的信号和槽机制,实现勾选状态改变时启动或关闭Matlab进程。

Qt中的QCheckBox与Matlab

在本篇文章中,我们将探讨Qt框架中的QCheckBox和Matlab之间的关联。QCheckBox是Qt中的一个控件,用于实现复选框功能,而Matlab是一种强大的数值计算和科学编程环境。我们将通过编写一些示例代码来展示如何在Qt应用程序中使用QCheckBox,并与Matlab进行交互。

  1. 创建Qt应用程序
    首先,我们需要创建一个Qt应用程序,以便在其中使用QCheckBox和Matlab。以下是一个简单的Qt应用程序的示例:
#include <QApplication>
#include <QWidget>
#
我的qt5.15.2版本代码如下,请给出完整可执行代码,我是windows系统,代码中现在可以读txt文件,现在需要让代码支持以下功能:可以读写txt.mat.bin.格式的文件。代码如下(我没有安装matio库也不想安装matio库,我安装了matlab 2022a,希望可以调用我电脑上的matlab函数或者库等,实现读写mat格式等):#include "mainwindow.h" #include "ui_mainwindow.h" #include <QTimer> #include <QTime> #include <QSerialPort> #include <QSerialPortInfo> #include <QMessageBox> #include <QFileDialog> #include <QTextStream> #include <QtCharts/QChart> #include <QtCharts/QSplineSeries> #include <QtCharts/QValueAxis> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), timerDrawLine(nullptr), serialPort(nullptr), timer(nullptr), timersend(nullptr), dataRxNumber(0), Serial_State(false), dataBuffer(MAX_POINTS, 0.0) { ui->setupUi(this); QStringList serialNamePort; Chart_Init(); serialPort = new QSerialPort(this); // 新建一个 QTimer 对象 timer = new QTimer(this); // 信号和槽(使用新的连接语法) connect(timer, &QTimer::timeout, this, &MainWindow::TimerOut); /* 定时发送定时器 */ timersend = new QTimer(this); /* 定时器超时信号槽 */ connect(timersend, &QTimer::timeout, this, &MainWindow::on_SendDataFile_clicked); /* 定时器 */ timerDrawLine = new QTimer(this); timerDrawLine->start(100); connect(timerDrawLine, &QTimer::timeout, this, &MainWindow::DrawLine); connect(ui->timesendcheckBox, &QCheckBox::stateChanged, this, &MainWindow::TimeSendReady); // 绑定 HEX 发送 chexkBox 信号对应的槽函数 connect(ui->HexsendcheckBox, &QCheckBox::stateChanged, this, &MainWindow::SendDataHex); foreach(const QSerialPortInfo &info , QSerialPortInfo::availablePorts()){ serialNamePort << info.portName(); } QFont font("Microsoft YaHei", 10, QFont::Normal); // 微软雅黑。字体大小 10,Normal:正常,Bold 粗体,Black:黑体,Light:高亮 setWindowTitle(" sinetac V2.10 "); ui->uartbox->addItems(serialNamePort); // 引入当前串口 setFixedSize(930, 560); // 固定窗口的大小 ui->CloseUart->setEnabled(false); // 断开按键关使能 ui->RecvTextEdit->setFont(font
03-11
Qt中设置QCheckBox的CSS样式(实际为QSS样式)可以通过`setStyleSheet`方法来实现。以下是一些不同方面的设置示例: ### 设置选择框尺寸 默认的QCheckbox的方块可能太小,图标显示不清楚,可使用如下QSS配置方块的尺寸: ```css QCheckBox::indicator { width: 90px; height: 60px; } ``` 在代码中使用: ```cpp QCheckBox *checkbox = new QCheckBox("Example", this); checkbox->setStyleSheet("QCheckBox::indicator {width: 90px; height: 60px;}"); ``` ### 设置选中和未选中时的文本颜色 ```css QCheckBox:checked { color: #DEFBFF; } QCheckBox:unchecked { color: gray; } ``` 代码使用示例: ```cpp QCheckBox *checkbox = new QCheckBox("Example", this); checkbox->setStyleSheet("QCheckBox:checked{color:#DEFBFF;}" "QCheckBox:unchecked{color:gray;}"); ``` ### 设置选择框的边框和背景 ```css QCheckBox::indicator:unchecked { border: 1px solid #174047; background-color: #031B1C; } QCheckBox::indicator:checked { background-image: url(:/Image/checkbox.png); background-repeat: no-repeat; background-position: center; } ``` 代码使用示例: ```cpp QCheckBox *checkbox = new QCheckBox("Example", this); checkbox->setStyleSheet("QCheckBox::indicator:unchecked{" "border:1px solid #174047;" "background-color: #031B1C;}" "QCheckBox::indicator:checked{" "background-image:url(:/Image/checkbox.png);" "background-repeat: no-repeat;" "background-position: center;}"); ``` ### 综合设置示例 ```css QCheckBox { border: none; /* 最外层边框 */ } QCheckBox::indicator { background-color: rgba(255, 255, 255, 0); border: 0px solid #b1b1b1; width: 30px; height: 30px; } QCheckBox:enabled:checked { color: rgb(255, 255, 255); } QCheckBox:enabled:!checked { color: rgb(255, 255, 255); } QCheckBox:enabled:hover { color: rgb(0, 200, 0); } QCheckBox:!enabled { color: rgb(80, 80, 80); } QCheckBox::indicator:unchecked { image: url(:/pic/1441292778_351283.png); } QCheckBox::indicator:unchecked:hover { image: url(:/pic/1441292778_351283.png); } QCheckBox::indicator:unchecked:pressed { image: url(:/pic/1441292778_351283.png); } QCheckBox::indicator:checked { image: url(:/pic/1441292784_170770.png); } QCheckBox::indicator:checked:hover { image: url(:/pic/1441292784_170770.png); } QCheckBox::indicator:checked:pressed { image: url(:/pic/1441292784_170770.png); } ``` 代码使用示例: ```cpp QCheckBox *checkbox = new QCheckBox("Example", this); checkbox->setStyleSheet("QCheckBox{ border: none;}" "QCheckBox::indicator{" "background-color: rgba(255, 255, 255, 0);" "border: 0px solid #b1b1b1;" "width: 30px; height: 30px; }" "QCheckBox:enabled:checked{ color: rgb(255, 255, 255); }" "QCheckBox:enabled:!checked{ color: rgb(255, 255, 255); }" "QCheckBox:enabled:hover{ color: rgb(0, 200, 0); }" "QCheckBox:!enabled{ color: rgb(80, 80, 80); }" "QCheckBox::indicator:unchecked { image: url(:/pic/1441292778_351283.png); }" "QCheckBox::indicator:unchecked:hover { image: url(:/pic/1441292778_351283.png); }" "QCheckBox::indicator:unchecked:pressed { image: url(:/pic/1441292778_351283.png); }" "QCheckBox::indicator:checked { image: url(:/pic/1441292784_170770.png); }" "QCheckBox::indicator:checked:hover { image: url(:/pic/1441292784_170770.png); }" "QCheckBox::indicator:checked:pressed { image: url(:/pic/1441292784_170770.png); }"); ``` ### 不同ID的QCheckBox设置不同样式 ```css * { outline: none; } QWidget { background-color: rgb(240,240,240); } QCheckBox { spacing: 5px; color: rgb(60,60,60); font-family: "Microsoft Yahei"; font-size: 11pt; } QCheckBox::indicator { width: 24px; height: 24px; } QCheckBox#csdnCheckBox::indicator:unchecked { image: url(:/Resources/unchecked.png); } QCheckBox#csdnCheckBox::indicator:unchecked:hover { image: url(:/Resources/unchecked_hover.png); } QCheckBox#csdnCheckBox::indicator:checked { image: url(:/Resources/checked.png); } QCheckBox#oschinaCheckBox::indicator:unchecked { image: url(:/Resources/star_unchecked.png); } QCheckBox#oschinaCheckBox::indicator:unchecked:hover { image: url(:/Resources/star_unchecked_hover.png); } QCheckBox#oschinaCheckBox::indicator:checked { image: url(:/Resources/star_checked.png); } ``` 代码使用示例: ```cpp QCheckBox *csdnCheckbox = new QCheckBox("优快云", this); csdnCheckbox->setObjectName("csdnCheckBox"); QCheckBox *oschinaCheckbox = new QCheckBox("OSChina", this); oschinaCheckbox->setObjectName("oschinaCheckBox"); QString styleSheet = "* { outline: none; }" "QWidget { background-color: rgb(240,240,240); }" "QCheckBox { spacing: 5px; color: rgb(60,60,60); font-family: \"Microsoft Yahei\"; font-size: 11pt; }" "QCheckBox::indicator { width: 24px; height: 24px; }" "QCheckBox#csdnCheckBox::indicator:unchecked { image: url(:/Resources/unchecked.png); }" "QCheckBox#csdnCheckBox::indicator:unchecked:hover { image: url(:/Resources/unchecked_hover.png); }" "QCheckBox#csdnCheckBox::indicator:checked { image: url(:/Resources/checked.png); }" "QCheckBox#oschinaCheckBox::indicator:unchecked { image: url(:/Resources/star_unchecked.png); }" "QCheckBox#oschinaCheckBox::indicator:unchecked:hover { image: url(:/Resources/star_unchecked_hover.png); }" "QCheckBox#oschinaCheckBox::indicator:checked { image: url(:/Resources/star_checked.png); }"; csdnCheckbox->setStyleSheet(styleSheet); oschinaCheckbox->setStyleSheet(styleSheet); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值