View Full Version : Unable to get the correct QWidget width after expansion

10th June 2013, 08:41
I am trying to embed a Qtreeview inside a QWidget. The user has the choice of expanding the QWidget. The width of the columns in the Qtreeview are calculated based on the current QWidget width. There are 5 columns in the treeview. Each column takes a fraction of the total QWidget width. I am using QWidget::width() function to get the current width of the widget. But even after expansion of the widget I am getting a constant number(100) as the QWidget width. I have also used SetStretchLastSection.

Illustration of the problem is as follows:

Normal Treeview Widget:

After Expansion:

Expected Behaviour:

Current Behaviour:

10th June 2013, 08:52
Wouldn't it be easier to just set the resize mode for the second column to Stretch?


10th June 2013, 09:05
I tried that. But the other columns should have their resize mode set to interactive. So, if I set the second column's resize mode as stretch, columns after it gets expanded in the opposite direction.

10th June 2013, 16:49
Ok, I'll probably don't fully understand your objectives.
But why do you use the parent widget's width and not that of the treeview itself?