50

I am new to QT, and I'm using QTableView, as shown below:

enter image description here

On the left side of the table, Qt is automatically showing a row number, as I've noted in red. How do I get rid of these numbers?

My other problem is, if I click any cell, only that cell is selected. How can I make it to where, when a user clicks a cell, the entire row is selected, like I noted in pink? For example, if I click the testApp-copy.itr cell then the entire third row should be selected.

jpyams
  • 4,030
  • 9
  • 41
  • 66
saravanan
  • 1,605
  • 6
  • 20
  • 25

1 Answers1

96

Use

table->verticalHeader()->hide();

to get the vertical header and hide it, and

table->setSelectionBehavior(QAbstractItemView::SelectRows);

to make QTableView only select whole rows. You may also want to specify the selection mode.

jpyams
  • 4,030
  • 9
  • 41
  • 66
Roman A. Taycher
  • 18,619
  • 19
  • 86
  • 141
  • 3
    The documentation makes it look like table.setSelectionBehavior(QAbstractItemView::SelectRows) is what you want to select a whole row. – Roman A. Taycher Oct 05 '10 at 07:08
  • 4
    You can also set these properties in the Designer in case you are using it. – Nils Feb 08 '13 at 14:25
  • 11
    Hijacking top Google search result: one thing that nobody ever mentions is that your data model needs to return the flag `Qt::ItemIsSelectable` before the table will select anything. http://doc.qt.io/qt-4.8/qabstractitemmodel.html#flags – Artfunkel Nov 08 '16 at 14:58