qt tableview得到行高
时间: 2023-08-19 12:09:18 浏览: 511
要获取Qt TableView的行高,可以使用`QTableView`的`rowHeight()`方法。该方法接受一个整数参数,表示要获取的行的索引。例如,要获取第一行的行高,可以使用以下代码:
```cpp
int rowHeight = tableView->rowHeight(0);
```
请注意,行高的默认值是-1,表示使用默认行高。如果要获取所有行的行高,可以使用循环遍历每一行的索引,并调用`rowHeight()`方法获取行高。
```cpp
for (int row = 0; row < tableView->rowCount(); ++row) {
int rowHeight = tableView->rowHeight(row);
// 处理行高
}
```
引用\[3\]中提到了设置默认行高的方法`verticalHeader()->setDefaultSectionSize(15)`,但是这个方法是用于`QTableWidget`的,而不是`QTableView`。在`QTableView`中,可以使用`verticalHeader()->setDefaultSectionSize(15)`来设置默认行高。
综上所述,要获取Qt TableView的行高,可以使用`rowHeight()`方法,并使用循环遍历每一行的索引来获取所有行的行高。
#### 引用[.reference_title]
- *1* *2* [QTableView设置自适应行高、列宽](https://blog.csdn.net/u013196348/article/details/130342240)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [如何设置QTableWideget和行高和列宽](https://blog.csdn.net/Hodors/article/details/127044010)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.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)
![zip](https://img-home.csdnimg.cn/images/20241231045053.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)