ok then you can follow the suggestion from @mrjj (in case you would have set a custom model you would have need to handle the Qt::SizeHintRole in your data() method)
or try to set a QStyledItemDelegate to the view and use your stylesheet.
bool eventFilter(QObject* watched, QEvent* event)
if( watched == comboBox ) // or watched->inherits("QComboBox") ??
// you may want to do additional checks here for a generic solution (like the combobox is really editable, it has a insert policy set, etc)
switch( event->type() )
QKeyEvent keyEvent( QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier );
QCoreApplication::instance()->sendEvent( watched, &keyEvent );
@tamlong0205 I think most of this can be done from C++ side.
You can add a function in the model which can return what type is the data for current index. This function will be called from QML and depending upon its value use a Loader to load the specific delegate.
Perhaps setting currentIndex in Component.onCompleted handler ?
Create a C++ function which will store in info in the model itself i.e When you change the index in ComboBox call this function and update the value there and may be maintain a role to store this update.
I realised it like the_ explained. In my case it is the easiest way and it works (in a combobox with a list of values from a related table, I want to know if the entered string is part of the list and if not (index = -1) I open a dialog to add a new value in the related table).
But I admit, QCompleter is also a smart solution. Maybe in the future...
don't they use QComboBox-like widgets to offer different colors, brush thickness etc?
Hm, I guess that's true, but I'd say it has more to do with QMenus and QToolButtons than QComboBox. But then again they are indeed similar in some ways. Oh well, the important thing is it's doable and quite easy ;)
I have found out that I can use setEditText(const QString &) to specify the default display text, like "-- Choose --". But, this works only with editable QComboBox widgets, which I wouldn't want to do. Besides, why is my non-editable QComboBox displaying a seemingly arbitrary string that has nothing to do with the provided index? Again, it is only the display text I am talking about, while the selectable items - the contents of the ComboBox - are perfectly fine.
How does this work to begin with? I have read the documentation on QComboBox numerous times and found nothing.
Thanks you :)
Why can't i set using? can't we do it for tableview? is it only for widgets?
'QAbstractItemView::setIndexWidget' : cannot convert parameter 2 from 'ComboBoxDelegate *' to 'QWidget *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast