Highlighting items in TreeView C++ BUILDER - c++

How can i change text color of some specifec item in TreeView?
TreeView is filled in program.
I mean i want to highlight some Treeview item by changing it text color.

You need to owner-draw the TreeView. It has OnCustomDrawItem and OnAdvancedCustomDrawItem events for that purpose. On a per-item basis, you can set the TreeView's Canvas->Font->Color property to whatever you want. Since you have access to the Canvas, you can draw whatever you want, not just customize the text.

Related

Win32 (C++) :- How to make a list item collapsible

I have a listbox in which multiple list items are there. I want to implement something like if we click on the list item, it will collapse and show the summary of the clicked item:
I have been searching this on the web for quite sometime but haven't got any good solution. I am very new to Win32. Any suggestions on how to approach this like which control should I use. Any help will be appreciated.
Standard ListBox and ListView controls do not natively support expanding/collapsing items, however it is possible to implement it in a ListBox with some extra work.
Give the ListBox the LBS_OWNERDRAWVARIABLE list box style to allow the list to contain items of different heights. When a new item is added to the list, the ListBox will send a WM_MEASUREITEM message to its parent window asking for the item's initial height. Return an appropriate height based on whether the item should be displayed as collapsed or expanded.
Once an item has been added to the list, you can send the ListBox a LB_SETITEMHEIGHT message to assign a new height for that item based on whether it should now be displayed collapsed or expanded. Then invalidate the ListBox to trigger a repaint of the items.
The LBS_OWNERDRAW... styles require you to manually draw each list item whenever the ListBox sends a WM_DRAWITEM message to its parent window. You can draw the requested item on the provided HDC however you want, such as with the DrawText() function, configuring its parameters based on whether the item's text is currently being displayed as collapsed or expanded. Also use the state information provided by the message itself to configure the HDC's font and background/foreground colors as desired (particularly important when rendering items in the selected and focused states).
With that in place, all you have left to do is make your click handler determine the index of the item being clicked on (via GetMessagePos(), ScreenToClient(), and LB_ITEMFROMPOINT), and then assign it a new height based on its new expanded/collapsed state, and let the resulting repaint draw the new text accordingly.

How to add QMenus or Qactions on a Widget like QlistWidget area as a list item?

Is there any way to add QActions as a list item on QListWidget?
I want to make a customization window which will show list of actions on a widget for move up, move down, Rename and other options. I'd like to display it on the widget same as it appears as a context menu.
I tried adding it as a list item with icon and text, but the look it not very good:
i) list items with blank icon are not aligning properly, even after adding a blank icon of size 16*16 is not taking up any space and text with icons & w/o icon are not aligning.
ii) I'm unable to add right-pointing black triangle at the right most, in-case of sub-menus cause somehow unicode character for this is not getting displayed on my Linux machine.
That's why I want to add QActions as it are getting popped at original place.
Any suggestions?
Yes I have a suggestion : do not try to make fancy widgets like this, users will not find it intuitive
You should find another way to implement this.
Imo, something like a QToolButton with a QToolButton::MenuButtonPopup popup mode will do the trick. This way, you can embed menu and sub-menus in a widget, using QToolButton::setMenu().

How can I wrap the item text in treeview control in WTL

I am maintaining a ATL/WTL project in which it contains a tree view. The class used for the tree view is CTreeViewCtrl. Now the client has asked to wrap the tree item text when it goes out of view though we can re-size the pane or scroll left of right anytime to see the content. It also shows the full string, when hidden, as a tool tip when mouse pointer is hovered on a tree item.
Is there any way I can set in the tree item or the tree view to wrap the text content.
Thanks
There's a way: do custom drawing of treeview's items while processing NM_CUSTOMDRAW message from treeview control, specifically the CDDS_ITEMPOSTPAINT drawing stage.
On custom drawing you draw multi-line text using ::DrawText() with DT_WORDBREAK flag.
In order to have enough space available for text to fit in use TVITEMEX structure's iIntegral field. You'll have to specify number of lines for each node by sending TVM_SETITEM message to treeview window with pointer to TVITEMEX as LPARAM. You'll have to recalculate number of lines for each of tree's nodes every time treeview's width changes (WM_SIZE).

CListBox item background

I need to set background CListBox background.
I can't find solution for set different colors for each item.
How can I do that?
To get different colors for each item you have to owner-draw the list box. That means you must paint each item yourself. See the CTRLTEST sample in MSDN.

Listview tristate checkbox

I have a listview in report style with checkboxes.
Is there any easy way to make the check box appear disabled? To give it a tristate sort of effect?
I want to have 3 states: Enabled, Disabled, and Unset.
The standard LVS_CHECKBOXES style does not support tri-state checkboxes. However, LVS_CHECKBOXES is internally implemented as a ListView-managed ImageList and normal ListView state indexes, so you can simply assign your own ImageList to the ListView, put three checkbox images into it, and set each ListView item's state index as needed. Then you just need to handle mouse messages for the ListView to switch between state indexes when clicking on an item's state image.