qt中QTablewidget setcurrwidget设置多个不重叠
时间: 2023-09-22 13:06:57 浏览: 184
在Qt中,如果要设置多个不重叠的当前单元格,可以使用QTableWidget::setCurrentCell()方法。该方法可以将指定的单元格设置为当前单元格,并将其滚动到可见区域。
例如,以下代码将设置三个不重叠的当前单元格:
```cpp
QTableWidget* tableWidget = new QTableWidget(this);
tableWidget->setRowCount(5);
tableWidget->setColumnCount(5);
// 设置第一个当前单元格
tableWidget->setCurrentCell(0, 0);
// 设置第二个当前单元格
QTableWidgetItem* item = new QTableWidgetItem();
item->setText("Cell 2");
tableWidget->setItem(2, 2, item);
tableWidget->setCurrentCell(2, 2);
// 设置第三个当前单元格
QTableWidgetItem* item2 = new QTableWidgetItem();
item2->setText("Cell 5");
tableWidget->setItem(4, 4, item2);
tableWidget->setCurrentCell(4, 4);
```
在上面的代码中,第一个当前单元格是表格的左上角单元格,第二个当前单元格是表格中间的单元格,第三个当前单元格是表格的右下角单元格。这些单元格不重叠,并且通过调用QTableWidget::setCurrentCell()方法进行设置。
阅读全文
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)