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.

Please look at image below:

The structure of pyqt table

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.

How to set content for horizontal header and vertical header?

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:

set text for table horizontal and vertical header

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

How to hidden horizontal header and vertical header?

To hidden horizontal header and vertical header we can do like this:

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

The effect is:

hidden pyqt table horizontal header and vertical header

Leave a Reply

Your email address will not be published. Required fields are marked *