7
$\begingroup$

This question was also asked on Wolfram Community.


As the title already says, my question is

Is there a way to change the highlighting color of the items that are marked/selected inside ListPicker?

One can somewhat influence the appearance by setting the background of selected items dynamically, but this is no real solution since the default highlighting is still overlayed

x={3};
ListPicker[Dynamic[x], {1 -> a, 2 -> b, 3 -> c, 4 -> d},
 Background -> {Dynamic[First[x]] -> Red}
]

As you can see, the color is not red but a mixture of red and the highlighting blue:

Mathematica graphics

I have already debugged how a ListPicker is converted into its box-form but the highlighting color cannot be influenced. I grep'ed through all style definitions but couldn't find something that looked promising. Additionally, I looked at the implementation of Experimental`RowSelector which seems to be a predecessor of ListPicker but there, the whole dynamic behavior is explicitly given and colors can be changed easily.

My last hope was that we can use Appearance for this as it is stated in the documentation that

When an object can be in several different states, the setting for Appearance can be given in the form {"con1"->app1,"cond2"->app2,...}.

but if this is possible at all and how to use it is not clear.

Has someone an idea that does not include hacking around and coming up with my own solution? Maybe someone from WRI could comment on this.

$\endgroup$
4
$\begingroup$

Not neat but what can we do:

x = {4};

ListPicker[ Dynamic[x]
  , # -> Framed[#2
      , ImageMargins -> 0, FrameMargins -> 5, FrameStyle -> None
      , Background ->  Dynamic[ If[MemberQ[x, #], Red, None, None] ]
    ] & @@@ {
        1 -> a, 2 -> b, 3 -> c, 4 -> d
    }
  , Spacings -> 0
  , FrameMargins -> 0
]

enter image description here

$\endgroup$
  • $\begingroup$ So basically overwriting the complete item with your own highlight-style.. Nice idea! +1 $\endgroup$ – halirutan May 29 '17 at 13:54
  • $\begingroup$ @halirutan but you never know if it works. I wasn't sure if I can completely overlap the default background. With native gui boxes FrameMargins may just miss a pixel row/column. Fortunately it worked here. $\endgroup$ – Kuba May 29 '17 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.