How to set QComboBox item data from QtDesigner
-
-
I'm able to add an item from code specifying the user data value:
void QComboBox::addItem(const QString &text, const QVariant &userData = QVariant())
But how to do the same using the build-in editor of QtDesigner?
I don't see any related property.
@Mark81 Double click on the QComboBox
-
@Mark81 Double click on the QComboBox
@Christian-Ehrlicher Are you sure? If I double click it opens the very same window I've already pasted above. But still I don't understand how to set the user data (not the text, of course).
-
@Christian-Ehrlicher Are you sure? If I double click it opens the very same window I've already pasted above. But still I don't understand how to set the user data (not the text, of course).
@Mark81
I do not see that you can associate data with items in Designer. So far as I can see, only from code. For one thing, the data is of anyQVariant
type, so it's not clear what a design-time editor would have to do to support that. You are perhaps assuming you would associate text, but it does not have to be, could be arbitrary binary data. -
@Mark81
I do not see that you can associate data with items in Designer. So far as I can see, only from code. For one thing, the data is of anyQVariant
type, so it's not clear what a design-time editor would have to do to support that. You are perhaps assuming you would associate text, but it does not have to be, could be arbitrary binary data. -
@Christian-Ehrlicher Are you sure? If I double click it opens the very same window I've already pasted above. But still I don't understand how to set the user data (not the text, of course).
@Mark81 said in How to set QComboBox item data from QtDesigner:
If I double click it opens the very same window
You should double click on the QComboBox you put into your QWidget. Then an editor shows up where you can enter some strings.
-
@Mark81 said in How to set QComboBox item data from QtDesigner:
If I double click it opens the very same window
You should double click on the QComboBox you put into your QWidget. Then an editor shows up where you can enter some strings.
@Christian-Ehrlicher yes, it is what I did. I can enter the text strings, but not the user data values. If I'm wrong, please attach a screenshot where you can show you are able to enter both.
-
@Christian-Ehrlicher yes, it is what I did. I can enter the text strings, but not the user data values. If I'm wrong, please attach a screenshot where you can show you are able to enter both.
@Mark81 You are correct. This is to complicated. But feel free to provide a patch.
-
@JonB ok, I got it. It's a good point, but from my point of view they could be add just the most common types: QString, int, double, etc... Of course if one needs a very specific type he has to do in code.
@Mark81 said in How to set QComboBox item data from QtDesigner:
they could be add just the most common types: QString, int, double, etc...
Well, they don't offer that... :)
If I were in a situation where I really wanted to add data field at design-time so I could do it in one place associated with where I did text, and if I wanted to add strings (or maybe numbers) for the data. I would do something like: put
#
followed by data value after text in Designer. LikeOff#0
orThis is long text#long
. And then at UI setup time walk my combo's text items and separate them out to reset text and the data on the#
. Yes it's ugly, but I might if I wanted the data specified at design-time.