4

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 table?

Thanks.

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
Narek
  • 38,779
  • 79
  • 233
  • 389
  • 1
    You can use the "Stretch last section" properties... But I guess you want both columns adapting to the Table's size and having the same width... I must say that I've sometimes experienced huge slowdown when I used automatic columns' resizing with a lot of elements/rows... I would advice simply to use "stretchLastSection", which is a kind of standard behavior... – Andy M Mar 27 '10 at 12:43

1 Answers1

6
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.

Maxim Popravko
  • 4,100
  • 3
  • 29
  • 43