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:
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:
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: