diff --git a/mainwindow.cpp b/mainwindow.cpp
index 8b8cd7c..a72649b 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -15,6 +15,8 @@ MainWindow::MainWindow(QWidget *parent)
, serial(new QSerialPort(this)) // 在构造函数中初始化 serial
{
ui->setupUi(this);
+ ui->groupBox->setMaximumWidth(250);
+ ui->groupBox_2->setMaximumWidth(250);
// 连接串口的 readyRead 信号到槽函数
connect(serial, &QSerialPort::readyRead, this, &MainWindow::onReadyRead);
#ifdef Q_OS_WIN
@@ -48,25 +50,44 @@ MainWindow::MainWindow(QWidget *parent)
ui->comboBox->addItems(portList);
// 创建 QStandardItemModel(表格数据模型)
- QStandardItemModel *model = new QStandardItemModel(3, 2);
+ QStandardItemModel *model = new QStandardItemModel(3, 4); // 3行4列(包括序号列)
// 设置表头标签
- model->setHorizontalHeaderLabels({"Name", "value"});
+ model->setHorizontalHeaderLabels({"序号", "文件名", "烧录地址", "文件大小"});
+
+ // 填充表格数据(假设我们填充一些假数据)
+ for (int row = 0; row < 3; ++row) {
+ // 创建序号列(根据行号动态填充)
+ QStandardItem *serialNumberItem = new QStandardItem(QString::number(row + 1));
+ model->setItem(row, 0, serialNumberItem);
+
+ // 创建其他数据列
+ model->setItem(row, 1, new QStandardItem("example.txt"));
+ model->setItem(row, 2, new QStandardItem("0x1000"));
+ model->setItem(row, 3, new QStandardItem("1024"));
+ }
// 插入数据
- model->setItem(0, 0, new QStandardItem("SN"));
- model->setItem(0, 1, new QStandardItem("123456789"));
- model->setItem(1, 0, new QStandardItem("BLE_NAME"));
- model->setItem(1, 1, new QStandardItem("G01-06"));
- model->setItem(2, 0, new QStandardItem(""));
- model->setItem(2, 1, new QStandardItem(""));
+ model->setItem(0, 1, new QStandardItem("/Users/yu/Qt/Work_Space/Off-line-Tools"));
+ model->setItem(0, 2, new QStandardItem("0xffffffff"));
+ model->setItem(0, 3, new QStandardItem("0xffffffff"));
+
// 将模型与视图关联
ui->tableView->setModel(model);
+ // 隐藏默认的行号列
+ ui->tableView->verticalHeader()->setVisible(false);
+ // 设置默认行号列宽度
+ // ui->tableView->verticalHeader()->setFixedWidth(30); // 设定行号列的宽度为 像素
//设置列宽
- ui->tableView->setColumnWidth(0,100);
- ui->tableView->setColumnWidth(1,160);
+ ui->tableView->setColumnWidth(0,60);
+ ui->tableView->setColumnWidth(1,280);
+ ui->tableView->setColumnWidth(2,100);
+ ui->tableView->setColumnWidth(3,100);
+
+ // 连接 QTableView 的 clicked 信号到槽函数
+ connect(ui->tableView, &QTableView::clicked, this, &MainWindow::onCellClicked);
}
@@ -75,6 +96,23 @@ MainWindow::~MainWindow()
delete ui;
}
+void MainWindow::onCellClicked(const QModelIndex &index) {
+ // 检查是否是第一列
+ if (index.column() == 0) {
+ // 获取选中的行
+ int row = index.row();
+
+ // 获取选择模型
+ QItemSelectionModel *selectionModel = ui->tableView->selectionModel();
+
+ // 选中整行
+ QItemSelection selection(ui->tableView->model()->index(row, 0), ui->tableView->model()->index(row, ui->tableView->model()->columnCount() - 1));
+ selectionModel->select(selection, QItemSelectionModel::Select);
+ }
+ qDebug() << "onCellClicked:" << index.column();
+
+}
+
void MainWindow::on_pushButton_clicked()
{
// 获取用户在 comboBox 中选择的串口设备
diff --git a/mainwindow.h b/mainwindow.h
index e594fdc..7fdddee 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -22,7 +22,7 @@ public:
private slots:
void on_pushButton_clicked();
void onReadyRead(); // 串口数据接收的槽
-
+ void onCellClicked(const QModelIndex &index);
private:
Ui::MainWindow *ui;
QSerialPort *serial; // 将 serial 定义为成员对象
diff --git a/mainwindow.ui b/mainwindow.ui
index 2be1282..0174ce5 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -14,246 +14,290 @@
ESP32系列脱机烧录
-
-
-
- 540
- 10
- 292
- 576
-
-
-
- -
-
-
- 烧录器
-
-
-
-
-
-
-
-
-
- QLayout::SizeConstraint::SetDefaultConstraint
-
-
-
-
-
- COM:
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
+
+
-
+
+
-
+
+
-
+
+
+
+ 15
+
+
+
+ 固件选择
+
+
+
-
+
+
+ 0
+
+
-
+
+
-
+
+
+ Qt::Orientation::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ 添加固件
+
+
+
+ -
+
+
+ 删除固件
+
+
+
+
+
+ -
+
+
+
+
+
+
+
+ -
+
+
+
+ 15
+
+
+
+ 镜像生成
+
+
+
-
+
+
-
+
- /dev/tty0
+ 文件:
-
- -
+
+
+ -
+
+
+ -
+
- /dev/tty1
+ 加载
-
-
-
- -
-
-
- 连接
-
-
-
-
-
- -
-
-
- QLayout::SizeConstraint::SetMinAndMaxSize
-
-
-
-
-
- QLayout::SizeConstraint::SetDefaultConstraint
-
-
-
-
-
- 烧录器信息:
-
-
-
- -
-
-
- Qt::Orientation::Horizontal
-
-
-
- 40
- 20
-
-
-
-
- -
-
-
- 一键复制
-
-
-
-
-
- -
-
-
-
- 0
- 30
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
- -
-
-
- 设备日志:
-
-
-
-
-
+
+ -
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ 15
+
+
+
+ 烧录器
+
+
+
-
+
+
+ 0
+
+
-
+
+
+ 0
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 0
+
+
+
+ COM:
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 0
+
+
+
-
+
+ /dev/tty0
+
+
+ -
+
+ /dev/tty1
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 0
+
+
+
+ 连接
+
+
+
+
+
+ -
+
+
+ QLayout::SizeConstraint::SetDefaultConstraint
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+ 烧录器信息:
+
+
+
+ -
+
+
+ Qt::Orientation::Horizontal
+
+
+ QSizePolicy::Policy::MinimumExpanding
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ 一键复制
+
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 150
+
+
+
+
+
+
+
+
+
+ -
+
+
+
+ 15
+
+
+
+ 设备日志:
+
+
+
-
+
+
+
+
-
-
-
-
-
-
-
- 10
- 430
- 511
- 151
-
-
-
- 镜像生成
-
-
-
-
- 220
- 30
- 61
- 31
-
-
-
- 加载
-
-
-
-
-
- 10
- 30
- 61
- 31
-
-
-
- 文件:
-
-
-
-
-
- 70
- 30
- 121
- 31
-
-
-
-
-
-
-
- 0
- 10
- 521
- 411
-
-
-
- 固件选择
-
-
-
-
- 10
- 20
- 501
- 41
-
-
-
- -
-
-
- Qt::Orientation::Horizontal
-
-
-
- 40
- 20
-
-
-
-
- -
-
-
- 添加固件
-
-
-
- -
-
-
- 删除固件
-
-
-
-
-
-
- 10
- 80
- 511
- 311
-
-
-
-
+
+