You are not logged in.

1

Sunday, December 11th 2011, 6:53pm

Standard Paradigm for QTableView Column Widths...?

Okay, I've done a ton of searching all over the internet, and found all the options for messing with column-widths in a QTableView, but so far I haven't found a good general paradigm for QTableView columns. I see I can use resizeSection to set fixed widths, and use QFontMetrics in order to compute specific widths, and get view-size properties and set columns as percentages. In fact there seems to be countless, completely different ways to do this, in general.

For instance, I have a table where I compute a solid initial fixed width for columns (0, 1, 4) and want columns (2, 3) to stretch with a 2:1 ratio if the widget is resized. Or I want to fit some columns to contents, but not others, or guarantee that some columns don't get cut off while others are allowed to be too small. It seems that most settings (like setStretch) is applied to all columns, not just some of them.

My existing idea is to implement a columnWidthCompute() method, which takes the current size of the QTableView, subtracts fixed-width columns, compute new widths for all columns and apply with horizontalHeader().resizeSection(col, width) for each. Assign this method as a slot to the QTableView.resized() signal. So far this is my leading idea, but I feel like there should be an easier way.,,

Any thoughts?

P.S. - I'm using PyQt, but I'm sure the paradigm would be the same between the different Qt variants

carpovpv

Beginner

  • "carpovpv" is male

Posts: 13

Location: Moscow

Occupation: teacher

  • Send private message

2

Sunday, December 11th 2011, 7:33pm

What about

Source code

1
Qt::SizeHintRole
in the function data of the underlying model for QTableView?
Did you examine it?