14

I'm struggling to set column width manually in a QTableView. Why doesn't this piece of code work?

tabb = new QTableView;
tabb->resizeColumnsToContents();

for (int col=0; col<20; col++) 
{
   tabb->setColumnWidth(col,80);
}

If I omit tabb->resizeColumnsToContents(); it still doesn't work.

Nicolas Holthaus
  • 7,763
  • 4
  • 42
  • 97
splunk
  • 6,435
  • 17
  • 58
  • 105

1 Answers1

27

You should set model first and after this you will be able to change ColumnWidth:

tabb = new QTableView;
tabb->setModel(someModel);

for (int col=0; col<20; col++) 
{
   tabb->setColumnWidth(col,80);
}
Jablonski
  • 18,083
  • 2
  • 46
  • 47