Qt equivalent of some MFC CListCtrl functionality
-
Some code I am attempting to port to Qt uses a customised version of the MFC CListCtrl control.
The specifics of the extension aren't critical to me but some of the base function is: The CListCtrl has the ability to display a checkbox, a State Icon and a Small or Large Icon in one of the columns (maybe only the first one):
From the documentation it seems that the recommendation is to use a QTreeWidget for this type of display control, but I can't see this type of function in QTreeWidget. I suspect setIcon will deal with one of these but the remainder have me puzzled.
Have I overlooked something while looking at the docs, or is this something that requires a custom widget, and if it is has anyone been there, done that?
-
Arrghh I had misunderstood the CListCtrl code in this case! These aren't actually two icons (even though it looks that way). It is one icon with two small images in it! Sorry - for my confusion reading someone else's code.
And thank you again for your help.
-
Hi
The views can show a checkbox.
https://forum.qt.io/topic/92530/configuring-checkbox-when-using-qtreewidget
Also icons. Not sure about the state icon what that represents?In any case, if you can what you want directly, you can always use a Delegate which allows for most things
if hand coded. -
I think the stateIcon meaning is whatever you choose it to mean
Thanks for the stuff about the checkBox, I certainly missed that!
I couldn't find a lot of tutorial stuff about the delegate classes.
Are you saying that I could add a stateIcon plus setter and getter to QTreeViewWidget and somehow persuade the code to draw the checkBox, standard Icon and state Icon? I looked at the code of qstyleditemdelegate and couldn't get my head round how it drew just the checkBox and standard icon, never mind how I might sub-class it to draw another icon in the first column
When I looked at TreeView (as I'd prefer to use a separate model) I couldn't even find an Icon attribute! ???? Am I totally in a mess here?
Thanks
David -
Hi,
Since you seem to have 4 different columns, you might not even need a delegate. You can use the DecorationRole for the image part.
You can check the Star Delegate Example for a complete custom delegate + editor.
-
Indeed, the roles apply to each cell.
So, yes, you'll have to go the delegate route for that column.
-
Can you clarify the issues I raised about TreeView and icons - I can't see how that works if there's no setIcon method.
Is it possible for a column to have more than one role at the same time? I'm beginning to think that I can't have a column that contains an Icon and a checkbox at the same time, never mind an additional icon! Or can I call QStandardItemModel::setItemData multiple times to assign the checkState and two icons to a an item?
D.
-
Arrghh I had misunderstood the CListCtrl code in this case! These aren't actually two icons (even though it looks that way). It is one icon with two small images in it! Sorry - for my confusion reading someone else's code.
And thank you again for your help.
-
Just to note, views may (and will) request data for several different roles for each cell. So in fact yes you can have text and icon at the same time as a custom text and background color. The item delegate has access to all the data that corresponding to the index it will draw for.