How to set QComboBox item data from QtDesigner
-
-
@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).
-
@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 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.
-
@Mark81 You are correct. This is to complicated. But feel free to provide a patch.
-
@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.