سؤال

I see this wierd behavoir happening with QComboBox, it doesn't update as soon as its contents change. To demonstrate the issue here is a sample code and some screen shots.

Initial widget enter image description here

Add Item to combobox enter image description here (See how the checkbox is overlapped)

Manually resized updates and adjusts the layout & comboboxenter image description here

#include <QApplication>
#include <QtGui>

int main(int argc, char* argv[])
{
    QApplication app(argc, argv);

    QWidget parentWidget;
    QCheckBox checker;
    QComboBox comber;
    QHBoxLayout layoot;

    comber.setEditable (true);
    comber.setSizeAdjustPolicy(QComboBox::AdjustToContents);

    layoot.addWidget (&comber);
    layoot.addWidget (&checker);
    parentWidget.setLayout(&layoot);

    parentWidget.show();
    return app.exec();
}

I tried update() and repaint() on the combobox and also the layout after the item is edited but doesn't have any effect. Do I really have to manually resize the widget for the combobox to readjust?? Is anyone aware of a fix for this problem??

Thank you.

CV

هل كانت مفيدة؟

المحلول

It sounds like a bug to me, especially if manually calling update on the layout is having no effect. Perhaps what you are seeing is this bug. Apparently that one is fixed in 4.8.0.

نصائح أخرى

I agree it's kinda weird behaviour... adding parentWidget.resize(parentWidget.sizeHint()) ; after adding text solved the problem, but it's more a hack than an answer.

edit : ok, did you try the QComboBox::AdjustToContentsOnFirstShow sizeAdjustPolicy instead ? Does it fit your needs ? At least it solves the problem even for an embedded widget as well

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top