开发者

Change table columns width on resizing window or splitter

开发者 https://www.devze.com 2022-12-24 03:17 出处:网络
Consider there is a QTablWidget and a QTextEdit. Both of them are in a horisontal QSplitte. Let the QTable widget has 2 columns.

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

精彩评论

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