Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent user from resizing columns of QTableWidget?

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?

like image 229
Septagram Avatar asked Jan 31 '12 11:01

Septagram


1 Answers

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().

like image 119
Septagram Avatar answered Sep 27 '22 22:09

Septagram