Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QTableView column width

Tags:

c++

qt

qtableview

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.

like image 919
splunk Avatar asked Oct 31 '14 18:10

splunk


1 Answers

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);
}
like image 123
Kosovan Avatar answered Nov 18 '22 02:11

Kosovan