11

I'd like to manage width of my columns in a table personally, but after resizing them from the code, I cannot figure out a way to prevent user from resizing them manually. I found out that QTableView has the columnResized() slot, and the only ways to do it I see are either subclassing QTableWidget or resizing columns again and again on the timer event.

Might there be an easier way?

Septagram
  • 9,425
  • 13
  • 50
  • 81

1 Answers1

32

It can be done using :

void QHeaderView::setSectionResizeMode (ResizeMode mode)
void QHeaderView::setSectionResizeMode (int logicalIndex, ResizeMode mode)

The horizontal header is reachable from a QTableWidget using horizontalHeader().

This is it:

ui->tMeal->horizontalHeader()->setSectionResizeMode (QHeaderView::Fixed);

Note that legacy (Qt4) applications should use setResizeMode().

Septagram
  • 9,425
  • 13
  • 50
  • 81