TListView Item Focus Theming - delphi

When using a TListView and themes are disabled in the Application, the focused and selected item appears something like this:
Notice in both images where the triangle is. The painted box for the item does not draw where the icon appears. In a TListBox the painted item fills the whole selected item.
How might I be able to get the icon part of the selected item to fill, just as it does with the text part?
I know TListBox renders like this, but I require the use of TListView for the Data property, also the TListView handles icons better via a TImageList.
Thanks.

You'll need to use the OnCustomDraw events of TListView. Within the event handler:
Determine if the item is selected
Determine if the control is focused
Draw the appropriate selection rectangle if the item is selected (grey if the control isn't selected, blue if it is)
Draw the text
Draw the image from the imagelist using TImageList.Draw
There are methods for doing these things, such as DrawText and FillRect.
Note that you can use TListBox rather than TListView if you'd rather. You indicated you need the Data property for items in the list, I'd assume to tie them up to your actual model objects. You can do this with anything that supports TStrings (such as TListBox.Items) using TStrings.Objects.

Related

Firemonkey styles - duplicate a certain style lookup to customize

In a Firemonkey project, I have a TListBox with numerous items. Depending on the state of any given item, I intend to show the Detail as either red or white (on a black background). Of course I need to use the styles to do this.
I right-click one of the TListBoxItem controls and choose "Edit Custom Style...". It's my understanding that it's supposed to produce a new copy of whatever the current style lookup is just for this one control. In my case, I had already set it to listboxitemrightdetail prior to trying to customize it. What I would expect is that when I make a change to the font color in this style and "Apply and Close", that one single list box item should get that change.
However, instead of that one, ALL of the items in this list box got that change. The change I made actually modified the listboxitemrightdetail rather than producing a copy of it just for that one control.
In the end, I intend to have two style lookups, for example listboxitemreddetail and listboxitemwhitedetail which I can toggle on each list item in runtime.
What am I doing wrong, and what's the appropriate way to duplicate a style lookup to have two different versions?

FMX progressbar color

Please be kind, I did my best with google, and found some guidance (also on StackOverflow), but none of it works for me.
FMX form with FMX Progressbar;
I only want to change the progressbar color from ugly yellow to cool skyBlue.
So far I've dropped a stylebook on the form;
I've added "progresscellstyle.htrack.hindicator" to the stylesheet designer;
It's the only one that even provides me with a color option (vs everything in "progressbarstyle treeitem") and that color does not influence my progressbar colour.
Please, a next step to decoding this problem if you could be so kind
Drop a TProgressBar on the form. Right click it and select Edit Custom Style. It should give you the style designer with a ProgressBar1Style1 object which contains htrack and vtrack.
htrack contains hindicator. Drop a TRectangle on the hindicator. Set the TRectangle to align Client. Change the Fill color as desired. Change the Stroke Kind to None.
vtrack contains vindicator. Drop a TRectangle on the vindicator. Set the TRectangle to align Client. Change the Fill color as desired. Change the Stroke Kind to None.
Close the style designer and save when it asks. This is one way to do it.
This may be a title old question, but the content about this is so rare that I think will be useful to future generations to have some info here.
To simply put, to change the color that will fill your bar you have to select a area in your BitmapLinks. To do that double click in the SourceLink property in the hindicator (a child of htrack in the tree view).
Then select a are that you will want to use as the filling, if none of the option pleases you, you may add a new BitMap to your StyleBook.
For the background color, just insert a rectangle inside htrack with a Client Alignment

Change Alternating Colors in Firemonkey TListView

Dropping a tlistview onto a form and checking the property 'AlternatingColors' to true, by default it will show a grey background on every other item on the listview.
My question is does anyone now how to change this color to something else?
Thanks,
You need to edit the style of TlistView.
Right-click on listview, choose "Edit Custom Style" and in the structure panel there are two items: "itembackground" and "alternatinfitembackground".
You can change the colors from there.

Positioning of custom list box item components in Delphi XE5, Firemonkey

I've customised the style of a Firmeonkey list box item in such a way that now it can consist of 4 TLables in it. Each of the lable has Alignment as alNone.
I'm setting position of each of them in my code whenever i need to add any item. I've observed that when my list has scroll bar and if first component is not visible (i.e. i've scrolled down enough) at that time if i re-add all the items again in list box, then the position of TLabels in first items (or items which are not shown) get distorted.
For setting positions I am using below code :
(tmpListBoxItem.FindStyleResource('txtCol2') As TLabel).Position.X :=
(tmpListBoxItem.FindStyleResource('txtCol2') As TLabel).Position.X + (tmpListBoxItem.FindStyleResource('txtCol2') As TLabel).Width;
Any suggesstions, how can i overcome this issue.
Regards,
Padam Jain
Firemonkey styles are repeatedly 'applied' and 'freed' as components appear and disappear from screen.
It is not enough to simply set properties of style objects once and expect those values to be remembered. What you need to do is either listen to the OnApplyStyleLookup event or override the ApplyStyle method of a custom component and use the same you have above to set the properties again.
This means you'll need somewhere to store the values you are going to set.
I would suggest for your situation that you subclass TListBoxItem so you can add suitable properties or fields and put your code in ApplyStyle.

How to change the way selection is drawn on a image in a TListView in Delphi?

I load icons from exe/dll/ico and I display them in a TListView set to vsIcon. The images are stored in a TImageList set as TListView.LargeImages.
So each item in TListView is an image + a small text below.
The user selects one or more and clicks on a button.
The problem is that the selection of the images looks "ugly":
I want to be drawn like on the desktop when you select a shortcut:
But I need that TListView to have the same "behavior" in other situations. I say this because I know that using OnCustomDraw events is generating problems in other "areas".
And since the images are available only at runtime I can't store them in resources as "selected". But I think I can "double" the images from TImageList, if it's necessary.
Is it possible..?
Thank you.
PS: I use Delphi 7.

Resources