Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, December 2007
updating the size of a QComboBox when items change


Message 1 in thread

I have some QComboBoxes that start out with no items. As certain parts 
of my program change state, the boxes will have items added depending on 
what the user does. Unfortunately, the QComboBox remains at its default 
sizeHint, so when I pop up the menu, all of the items are usually too 
long to fit in the menu nicely.

My QComboBox is in a QHBoxLayout. After adding the items, I want to tell 
the QComboBox to request the layout to update so it can grow to fit the 
items - just like it would if the items were added to the box from the 
start.

Calling updateGeometry() or layout()->activate() doesn't work.

Qt 4.3.3.

Any ideas?

-- 
 [ signature omitted ] 

Message 2 in thread

On torsdag den 6. December 2007, Paul Miller wrote:
> I have some QComboBoxes that start out with no items. As certain parts
> of my program change state, the boxes will have items added depending on
> what the user does. Unfortunately, the QComboBox remains at its default
> sizeHint, so when I pop up the menu, all of the items are usually too
> long to fit in the menu nicely.
>
> My QComboBox is in a QHBoxLayout. After adding the items, I want to tell
> the QComboBox to request the layout to update so it can grow to fit the
> items - just like it would if the items were added to the box from the
> start.
>
> Calling updateGeometry() or layout()->activate() doesn't work.

If there is a difference between the size you get when populating the combobox 
initially and when you populate it later and call updateGeometry(), then I'd 
say you need to write a bug report to Trolltech.

Bo.

-- 
 [ signature omitted ] 

Message 3 in thread

On Dec 6, 2007, at 5:52 PM, Paul Miller wrote:

> I have some QComboBoxes that start out with no items. As certain  
> parts of my program change state, the boxes will have items added  
> depending on what the user does. Unfortunately, the QComboBox  
> remains at its default sizeHint, so when I pop up the menu, all of  
> the items are usually too long to fit in the menu nicely.
>
> My QComboBox is in a QHBoxLayout. After adding the items, I want to  
> tell the QComboBox to request the layout to update so it can grow  
> to fit the items - just like it would if the items were added to  
> the box from the start.

The default value of QComboBox::sizeAdjustPolicy is  
AdjustToContentsOnFirstShow. Change it to AdjustToContents.

Brad

-- 
 [ signature omitted ]