What is Horizontal Header and Vertical Header in PyQT Table, How to Change and Hidden Them – PyQT Tutorial

By | December 12, 2019

To create a table correctly in pyqt, we should know what is horizontal header and vertical header. How to set text and hidden them? In this tutorial, we will discuss this topic for pyqt beginners.

The structure of pyqt table

The table contains 3 parts in pyqt, they are: horizontal header, vertical header and table body.

From image we can find: horizontal header is at the top of table, vertical header is in left, table body is an area to save data.

To set text content for horizontal header and vertical header is very easy, here is an example:

table.setHorizontalHeaderLabels(['id','Name','Age','Sex','Address'])
table.setVerticalHeaderLabels(['Col 1','Col 2'])

The effect is:

We can find if we have not set text for some columns in vertical header, the content of which will be column number.

table.horizontalHeader().setVisible(False)
table.verticalHeader().setVisible(False)