18

I'm using Qt4 to create a table, using the QTableWidget class.

Problem is: I want to hide the row labels (i.e. the numbers). I just care about columns. I want to get this:

alt text
(source: ldc.usb.ve)

How can I accomplish this?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Emiliano
  • 22,232
  • 11
  • 45
  • 59

3 Answers3

50

I was wondering about the same thing. However, I was too lazy to find a solution till you asked. (Thanks!!). Anyway, here is the code that worked for me:

    table = QtGui.QTableWidget()
    table.verticalHeader().setVisible(False)

These are actually QTableView's methods. Since you use a QTableWidget which is a child of QTableView, everything works out.

I am not sure whether this is the best way to do this, but the QHeaderView documentation recommends this method. To quote the PyQt4 docs-

Appearance

QTableWidget and QTableView create default headers. If you want the headers to be visible, you can use setVisible().
Note: Each header renders the data for each section itself, and does not rely on a delegate. As a result, calling a header's setItemDelegate() function will have no effect.
batbrat
  • 5,155
  • 3
  • 32
  • 38
  • Thanks, it works! I'm lazy, too. I gave up when I wasn't able to find a property in the qt-Designer which allowed me to do that. – Emiliano Feb 24 '09 at 07:36
  • As of Qt Designer 4.5 (I believe), you can set both the vertical and horizontal header properties right in the property editor. – Krsna Jul 27 '09 at 15:14
  • Cannot edit answer ("edit queue full"), because is in little detail wrong: "False" --> "false". Just to be correct and make it "copy/pastable". – Jesko Jul 18 '22 at 13:05
6

You can also put your data in a QTableView object and hide the vertical row header with a hide() function. Here is the sample code,

 QTableView *empview = new QTableView();
 empview->verticalHeader()->hide();
0

Now you can just use method:

setHeaderHidden(true);

inherited from QTreeView. It was introduced in Qt4.4.