qtableWidget冻结窗格
时间: 2023-08-17 15:04:41 浏览: 61
要冻结QTableWidget的窗格,您可以使用setHorizontalHeader和setVerticalHeader方法来设置水平和垂直表头,并将它们设置为QHeaderView的Fixed属性。这将阻止表头滚动,并使其保持固定在窗口中。以下是一个示例代码:
```python
from PyQt5.QtWidgets import QApplication, QTableWidget, QHeaderView
app = QApplication([])
table = QTableWidget(5, 5)
table.setHorizontalHeaderLabels(['Column 1', 'Column 2', 'Column 3', 'Column 4', 'Column 5'])
table.setVerticalHeaderLabels(['Row 1', 'Row 2', 'Row 3', 'Row 4', 'Row 5'])
# 设置水平表头为固定
horizontal_header = table.horizontalHeader()
horizontal_header.setSectionResizeMode(QHeaderView.Fixed)
# 设置垂直表头为固定
vertical_header = table.verticalHeader()
vertical_header.setSectionResizeMode(QHeaderView.Fixed)
table.show()
app.exec_()
```
运行这段代码,您将看到QTableWidget的表头被冻结在窗口中,不会随着滚动而移动。
相关推荐
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)