7

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 );
4

2 回答 2

3

这是不可能的,至少在 Qt Designer 2.5.2 中是不可能的。Designer 仅提供一组有限的定制。

于 2013-02-21T15:20:36.153 回答
1

正如@UmNyobe 所说,设计师不可能,但你可以使用这个技巧至少在视觉上将宽度设置为你想要的。

将此代码添加到对话框的析构函数中,它将打印出每列的列宽,以及树小部件和对话框本身的宽度。

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();
}

然后你可以运行你的程序,将列宽调整到你想要的,当你关闭对话框时,它会打印出你需要的宽度,如下所示:

第 0 列:110
第 1 栏:110
第 2 栏:110
第 3 栏:110
树小部件宽度:440,对话框宽度:543

这并不多,但总比在没有视觉反馈的情况下猜测哪些宽度看起来不错要好。

于 2016-06-02T08:43:18.407 回答