PDA

View Full Version : QComboBox does not resize with setModel()



Wim
4th December 2007, 05:22
I am using Qt version 4.3.1

I create a QComboBox with the QComboBox::AdjustToContents property set. The problem is that the size of the combobox is not adjusted when I change the model with setModel() after the combobox is displayed. Calling update() or adjustSize() after setModel() also do not work.

The only thing that seems to work is to insert and remove a dummy item, but that doesn't look very smart...

Can anyone tell me if there is a better way to tell QComboBox to adjust its size after a model change?

Thanks in advance.

jpn
4th December 2007, 07:25
I agree QComboBox should adjust its size hint when the model is changed. I suggest reporting this to Trolltech via Task Tracker (http://www.trolltech.com/developer/task-tracker) (if not already reported).

According to QComboBox sources, you could work it around by
- sending a QEvent::StyleChange, QEvent::FontChange (or QEvent::MacSizeChange)
- inserting or removing a row to/from the model
- changing any data of the root model index children
- changing size adjust policy to something else and then back
- changing minimum contents length
- changing icon size
even though none of them is that smart way. :) Each of these methods invalidates the current size hint and causes it to be recomputed.

Wim
4th December 2007, 07:58
I will submit a bug report to Trolltech. Thanks for your help.

Wim
4th December 2007, 23:29
Trolltech has created task ID 190205 to deal with this problem

They suggest "changing the size adjust policy before setting the new model and then change it back again afterwards, as it seems to be the least "intrusive" workaround".