July 22, 2011

amban amban
Lab Rat
46 posts

[Solved] Setting size of QTableView Header

 

Hi,
I have created a QTableView with QStandardItemModel. I have set the header as follows:

  1. QString headerlist ;
  2. headerlist << c1 << c12<< c123;
  3. mytable->setHorizontalHeaderLabels(headerlist);

I want to set my header size on the basis of size of string in headerlist. E.g. here size of col1 is 2 , col2 is 3 …and so on….
Please suggest a way to do it. I see resizeSection() as one of the solutions. Is there any other way ?

Thanks

2 replies

July 22, 2011

aureshinite aureshinite
Lab Rat
38 posts

Try:

  1. table->resizeColumnsToContents();

If the data get out of display area, it will add scrolls. If you also want the table to adjust to display all the columns, you need to do a bit more.

July 22, 2011

amban amban
Lab Rat
46 posts

Hey Thanks,
I think this is good for me.

 
  ‹‹ what will be the most suitable input method implmentation?      [SOLVED] Building Qt 4.8 beta fails on "./configure" ››

You must log in to post a reply. Not a member yet? Register here!