简体   繁体   中英

Qt custom delegates

I have custom model with different data types like string (file path) or double which should be edited using combobox with a few items.
It is not clear for me why delegates should be applied to views and not to models...

So, should I pass some kind of flag from my model and then use different delegates for those items according to those flags?
What is the best practice to make it?

EDIT: I'll try to clarify my question:
I have model with the map (key - value (structure that can contain different types like QVariant)) and it's necessary to set different delegates for each row of my, say, QTableView.
What is the best way to pass some "flag" for every item from my model and then handle this flag to set appropriate delegate for the given row?

EDIT2: This model-view pair is for storage and editing software options with different types.

From the docs :

Unlike the Model-View-Controller pattern, the model/view design does not include a completely separate component for managing interaction with the user.

Delegates are supposed to tackle the "how" in "how should users interact with my data" (that's why I highlighted "interaction").

For your case, that very "double" field you provided, depending on it's interpretation, we could use a line edit (eg exact toleration), spinbox, or even some sort of color select (interpret the value as a color). Even more, one could use a line edit with some sort of color scale for the widget to make it more clear what consequence that value may have.

Correct way? They're tools, not one better than other but rather "one to tackle a specific problem". Can't tell what's the correct way from the info provided.

I suggest re-asking the question with much more info if you still have doubts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM