Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Button color change when selecting/deselecting (toggle selection)

Hi All,

I want to change the color of a button depending on whether the button is activated or deactivated.

I tried the following:

- Setting up a variable Button

- Set variable on Button Click (Variable = vbutton, Value = 1)

Then I set up a calculated button color:

If(vButton = 1, RGB(20, 255, 8), RGB(247, 159, 8,))

The result is, that the button color changes when selecting the button. So far so good. I want the button color to change back to the original color though when I am pressing the button again (which means "deselection" in my application, because I defined a toggle selection on button click as well).

How can I do this?

Thanks very much in advance

Rgds Stephan

1 Solution

Accepted Solutions
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

Change the value in the action to the expression:

=If(vButton = 0, 1, 0)

This will toggle the button between 1 and 0. Your colour expression should work fine.

HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

View solution in original post

6 Replies
MK_QSL
MVP
MVP

like this?

Update : Change color according to your need.

jonathandienst
Partner - Champion III
Partner - Champion III

Hi

Change the value in the action to the expression:

=If(vButton = 0, 1, 0)

This will toggle the button between 1 and 0. Your colour expression should work fine.

HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
nizamsha
Specialist II
Specialist II

PFA

maxgro
MVP
MVP

set variable should be

=if(vButton=1,0,1) or as Jonathan suggest

and calculated color should be

If( vButton = 1, RGB(20, 255, 8), RGB(247, 159, 8))

instead of (removelastcomma)

If(vButton = 1, RGB(20, 255, 8), RGB(247, 159, 8,))

you can use an input box to check your variable

1.png

Not applicable
Author

Thanks all, this really worked well - I was not aware of the 0,1,0 logic.

Bloody beginner me

Not applicable
Author

Follow these easy steps

1. Create a variable vChange and assign value to 1

2. Select a button object and give proper name.

     In the button properties

      -> In general tab Color property-> Add calculated color expression : =If(vChange=1,Green(),Red())

     In the Actions tab-> Add actions as Setvariable

                              -> Variable : vChange (without "=")

                              -> Value : =If(vChange=1,0,1)

Now click and see