PDA

View Full Version : ItemDelegate show text intead of number



^NyAw^
6th March 2015, 10:55
Hi,

I have a QTreeView with a model that contains values from 0 to 5(IDs)
What I want is to display "Circle" when value is 0, "Square" when it is 1, ...
Have I to fill the model with the texts instead of the IDs? Or can I change what the view shows.
When the user edits the value I open a ComboBox that have an Icon and a text and I want to show something similar when the item is not in editting mode.

Thanks,

anda_skoa
6th March 2015, 12:28
Your delegate can paint whatever you want, no need to change the view

Cheers,
_

^NyAw^
13th March 2015, 12:32
Hi,

My Delegate shows what I want and I have editors like QComboBox working well. The problem now is that I don't know how to show my own editor.

What I have done is to create a QWidget inherited class that contains some checkBoxes (created using QtDesigner). On "createEditor" method I create a object of this class an return it as editor. I can see(on debugger) that the editor is initialized well but it is not displayed. So the problem now is to display the widget that I created on QtDesigner.

Thanks,

anda_skoa
13th March 2015, 16:13
What have you checked already?

That the constructor of the editor widget is called?
That the showEvent() method of the widget is called?

Cheers,
_

^NyAw^
13th March 2015, 17:03
Hi,

Searching in the forum I found this http://www.qtcentre.org/threads/54205-Creating-Custom-Widgets-With-QStyleItemDelegate?highlight=editor+delegate that explains that the problem is because the size of my widget is grater than the available space.

My widget is greater than the cell space and I want to show the widget like a popup widget that overlays the cell. It's something like the attached image11015

Thanks,

wysota
14th March 2015, 00:21
It's very unusual to do something like that. Usually you'd use a combobox to show such a large list. Are those options mutually exclusive or not?

^NyAw^
16th March 2015, 09:36
Hi,

The options are to select the Outputs of an acquisition card. The user can select wich Outputs to be active on each case.
For example, on case 0 the user could select to enable the out0 and out1 and on case 1 enable out1, so the outs are not exclusive.

Thanks,

wysota
16th March 2015, 11:42
You can follow the same rule that QComboBox follows -- make your editor open a popup window which lists the outputs to be selected. Alternatively just use a combo box with a model with checkable entries.

^NyAw^
16th March 2015, 17:11
Hi,


You can follow the same rule that QComboBox follows -- make your editor open a popup window which lists the outputs to be selected
I have been inspectiong QComboBox code but I'm not able to understand why its able to show the list of items.


Alternatively just use a combo box with a model with checkable entries.
This is what I'm trying with no luck.

Thanks,

wysota
16th March 2015, 19:47
I have been inspectiong QComboBox code but I'm not able to understand why its able to show the list of items.
When you click it, it shows another widget which happens to be a QListView showing a model of its items.


This is what I'm trying with no luck.
Just set a custom model on the combobox.