PDA

View Full Version : Updating layout after adding context to a QComboBox



dparks
18th February 2011, 00:03
Hello,

I have a QComboBox where the size adjust policy is set to 'AdjustToContent'. During execution of my program I add content to this widget. It resizes to fit the content even though there is insufficient space for it to do so. That is, it overlaps with the widget next to it. Resizing the screen causes the QComboBox to shrink. It is now as large as possible without overlapping the next widget. This is the behaviour I would expect.

My question is how to I get it to be 'as large as possible' immediately after adding new content. I've tried calling updateGeometry(), update(), layout()->update(), etc... without any effect. It seems like I need to have the layout recalculate the best size for all widgets, but am unsure of how to do this (I though that was the point of layout()->update()).

Thanks for any and all help.

Cheers,
Donovan

chenna
30th November 2011, 20:29
Hi,
Just curious if you were able to figure out the solution for this problem?? I am having the same problem

Best,
CV

myta212
1st December 2011, 07:46
Hi,
This is simple. You must set QComboBox SizeAdjustPolicy. This is a sample code :


ui->comboBox->addItem(str);
ui->comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);


With this code, your layout display will update after adding new item.
Thank you.

Best regards,

Toto

chenna
1st December 2011, 16:49
Hi,
This is simple. You must set QComboBox SizeAdjustPolicy. This is a sample code :


ui->comboBox->addItem(str);
ui->comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);


With this code, your layout display will update after adding new item.
Thank you.

Best regards,

Toto

Well I already have SizeAdjustPolicy set to 'AdjustToContents' for my combobox. So when the item text changes it resizes and overlaps with another item in the widget. Once I resize the whole window manually thats when the combobox updates and resizes so that it doesn't overlap. I tried update(), repaint() for the widget and the combobox after the item is added but doesn't help. I have to manually resize for it to readjust with the layout

CV