borisbn
borisbn

Reputation: 5054

Set column width for QTableWidget in designtime

I cannot find any information for the following question: is there a possibility to set width to columns for QTableWidget in designtime. When I opened ui-file in text editor, I found, that columns are declared like this:

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

I tried to add some properties like width, but had no success.

The only question I found at qtcentre.org is this. But unfortunaly it is without an answer.

Thank you for advise (even if it would be "You can't").

P.S. Please, do not answer, that I can do it in runtime like this:

table->headerView()->resizeSection( columnIdx, width );

Upvotes: 7

Views: 9916

Answers (2)

sashoalm
sashoalm

Reputation: 79467

As @UmNyobe said, it's not possible with designer, but you can use this trick to at least visually set the widths to what you want.

Add this code to the dialog's destructor, and it will print out the column width of each column, and 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 then you can run your program, adjust the column widths to what you want, and when you close the dialog it will print out what the widths that you need, like this:

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

It's not much but it's better than trying to guess what widths look good without visual feedback.

Upvotes: 2

UmNyobe
UmNyobe

Reputation: 22890

It is not possible, at least not with Qt Designer 2.5.2. Designer only offer a limited set of customization.

Upvotes: 3

Related Questions