Set column width for QTableWidget in design mode

I can not find any information on the following question: is it possible to set the column width for QTableWidget at design time . When I opened the ui file in a text editor, I found that the columns are declared as follows:

 <column> <property name="text" > <string>My column name</string> </property> </column> 

I tried to add some properties, for example width , but did not succeed.

The only question I found on qtcentre.org is this . But unfortunately, this is not an answer.

Thanks for the tip (even if it is "You Can't").

PS Please do not reply that I can do this at runtime as follows:

 table->headerView()->resizeSection( columnIdx, width ); 
+4
source share
2 answers

This is not possible, at least not with Qt Designer 2.5.2. The designer offers only a limited set of settings.

+3
source

As @UmNyobe said, this is not possible with the designer, but you can use this trick to visually set the width according to what you want.

Add this code to the dialog's destructor, and it will print the column width for each column, as well as the width of the tree widget and the dialog itself.

 SettingsDialog::~SettingsDialog() { QHeaderView *header = ui.treeWidget->header(); for (int ii = 0; ii < header->count(); ++ii) { qDebug() << "column" << ii << ":" << header->sectionSize(ii); } qDebug() << "tree widget width: " << ui.treeWidget->width() << ", dialog width:" << width(); } 

So, you can run your program, adjust the width of the columns as you want, and when you close the dialog, you will see what widths you need:

  column 0: 110
 column 1: 110
 column 2: 110
 column 3: 110
 tree widget width: 440, dialog width: 543 

This is not much, but better than trying to guess what widths look good without visual feedback.

0
source

All Articles