开发者

Change table columns width on resizing window or splitter

Consider there is a QTablWidget and a QTextEdit. Both of them are in a horisontal QSplitte. Let the QTable widget has 2 columns.

The problem is to resize the table columns' width as you do resize operation by moving the splitter with mouse. Are there any options to may colums to be resized synchornosly with the tab开发者_如何转开发le?

Thanks.


QHeaderView *header = ui->tableWidget->horizontalHeader();
header->setResizeMode(QHeaderView::Stretch);

This code sets all columns of ui->tableWidget to equal width and let it change automatically. And take a look on QHeaderView description in docs, you can do almost anything you can imagine with table columns with this API.

Sad, but you can't set any stretch factor or smth., if you need relational column widths not to be equal, but you still can reimplement sizeHint() or resize sections when header's geometriesChanged fires.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜