PDA

View Full Version : QCombobox contents not adjusting itself properly



anju123
4th January 2008, 08:25
I am creating a combo box with the default properties. The problem comes when the options in the combo box has more width then the combobox width. I do not want the combobox to resize as it has fixed width. I can see that for all the options the Combobox itself add abbreviated text, but for the selected text it gives a truncated effect, I want a consistent behaviour i.e the abbreviated text even on the selected option.
Does anybody has an idea about this?
Please see the attached screenshot .

jpn
4th January 2008, 08:36
Take a look at QComboBox::sizeAdjustPolicy.

wysota
4th January 2008, 08:40
I'm afraid it might be hard to achieve. The "selected" text is handled by a line edit that should truncate the text that doesn't fit instead of eliding it like the popup does through the delegate. You can probably subclass QComboBox and try to reimplement the paint event, but success is not guaranteed. It might be a good idea to suggest a needed change to Trolltech to allow eliding text in the combobox though. If GUI design rules allow it, there is no reason not to implement it.

maxpyne
12th February 2016, 18:11
I have used following logic to address this problem, it worked for me,

QComboBox cb;
cb.setMinimumContentsLength(20); // set anything > 0
cb.setSizeAdjustPolicy(QComboBox::AdjustToMinimumC ontentsLength);

fuerback
6th April 2016, 21:11
comboBox->view()->setTextElideMode(Qt::ElideNone);