Changing the width of table columns when resizing a window or separator

Consider what QTablWidget and QTextEdit are. Both are in horizontal QSplitte. Let the QTable widget have 2 columns.

The problem is changing the width of the columns of the table as you resize the operation by moving the delimiter with the mouse. Are there any options for resizing columns synchronously with the table?

Thanks.

+4
source share
1 answer
QHeaderView *header = ui->tableWidget->horizontalHeader(); header->setResizeMode(QHeaderView::Stretch); 

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

Sadly, you cannot set the stretch factor or smth. If you need the width of the relational columns so that they are not equal, but you can still override the sizeHint () parameters or resize with the header geometry.

+6
source

Source: https://habr.com/ru/post/1305300/


All Articles