Python 创建具有2个或更多标题行的QTableWidget
我想要一个有两行“header”的QTableWidget。基本上,我希望表格的前两行不垂直滚动。例如:Python 创建具有2个或更多标题行的QTableWidget,python,pyqt,Python,Pyqt,我想要一个有两行“header”的QTableWidget。基本上,我希望表格的前两行不垂直滚动。例如: Header 1 | Header 2 __________________ Header 3 | Header 4 __________________ Data | Data __________________ Data | Data __________________ Data | Data __________________ Data | Dat
Header 1 | Header 2
__________________
Header 3 | Header 4
__________________
Data | Data
__________________
Data | Data
__________________
Data | Data
__________________
Data | Data
__________________
我想防止在用户向下滚动时,4个标题(前两行)中的任何一个都无法从屏幕上滚动
无论如何,我看不到在Qt中添加额外的标题行或防止滚动单个行。也许有一种棘手的方法可以做到这一点,那就是有两个实际的表,其中一个表有一行作为标题?我找到了一种方法来做到这一点,尽管方法有些模糊。我确实找到了一个很好的例子,说明了如何做类似的事情,但是使用了列而不是标题行
Qt中指向“frozencolumn”示例的链接已失效,下面是正确的链接:如何将模型的headerData函数返回的数据连接到用作标头的QTableView的数据值?你如何捕捉QHeaderView类的所有信号?
def resize(self):
"""
Called when we know the data table has been setup by Qt so we are
guaranteed that the headers now have a width, etc.
There is no other way to guarantee that your elements have been sized,
etc. by Qt other than this event.
"""
# Make the width of the vertical headers on the header table the same
# size as the initialized width of the data table (data table widths
# are setup automatically to fit the content)
width = self._data_table.verticalHeader().width()
self._header_table.verticalHeader().setFixedWidth(width)
def selectAll(self):
"""Select all data in both tables"""
for table in [self._header_table, self._data_table]:
for row in xrange(table.rowCount()):
for col in xrange(table.columnCount()):
item = table.item(row, col)
table.setItemSelected(item, True)