Originally Posted by
L.Marvell
What do you think about?
Ok, that's an interesting bug..
QComboBox caches its size hint. The combo box of yours ends up calculating its size hint when the designed form is loaded:
size = size.expandedTo(MainWindow->minimumSizeHint()); // thanks to this line in generated ui_mainwindow.h
MainWindow->resize(size);
QSize size(400, 318);
size = size.expandedTo(MainWindow->minimumSizeHint()); // thanks to this line in generated ui_mainwindow.h
MainWindow->resize(size);
To copy to clipboard, switch view to plain text mode
QComboBox should invalidate it's size hint when a new model is set. Because it doesn't, the combo remains at cached size which was calculated when there were no items at all (defaults to width of 7 'x' characters).
A workaround is to change the order of statements like this:
MyMainWindow window; // let combo box calculate its initial size hint (designed form is loaded in MyMainWindow constructor)
window.combobox()->setModel(&model); // this does not cause size hint recalculation
model.setQuery("select * from person"); // but this one does (data of the model changes)
window.combobox()->setModelColumn(2);
window.combobox()->setCurrentIndex(0);
QSqlQueryModel model; // do not set the query yet
MyMainWindow window; // let combo box calculate its initial size hint (designed form is loaded in MyMainWindow constructor)
window.combobox()->setModel(&model); // this does not cause size hint recalculation
model.setQuery("select * from person"); // but this one does (data of the model changes)
window.combobox()->setModelColumn(2);
window.combobox()->setCurrentIndex(0);
To copy to clipboard, switch view to plain text mode
Bookmarks