Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
buddhabang
Contributor III
Contributor III

Creating dynamic buttons with colours

Hi everyone, i thought i'd share the following description of how to make dynamic buttons - In this instance there will be two buttons which will toggle color depending on which one you click. Here:

    • 1. Create a variable called vbutton1 and set its value to 0
    • 2. Create a 2ndvariable called vButton2 and set its value to 0
    • 3. Create 1st button
    • 4. In General Tab, click the coloured shape
    • 5. In Base Color section, tick Calculated, then the three dots…
    • 6. if(vButton1=1, rgb(0,0,0), rgb(255,255,255))
    • 7. In Action Tab, Add following actions to set the Button1 properties:
    • Type = External / Action =Set Variable  -OK
    • Variable = vButton1
    • Value = 1


Add another Action

    • Type = External / Action =Set Variable  -OK
    • Variable = vButton2
    • Value = 0

        Then redo steps 3 to 5 to create the 2nd Button 


    • 6'. if(vButton2=1, rgb(0,0,0), rgb(255,255,255))
    • 7'. In Action Tab, Add following actions to set the Button2 properties:
    • Type = External / Action =Set Variable  -OK
    • Variable = vButton2
    • Value = 1

Add another Action

    • Type = External / Action =Set Variable  -OK
    • Variable = vButton1
    • Value = 0

Done. Adjust and add a clear button to exercise, or select specific fields in your application.

Hint: Use Select in Field as action type.

Ifyou're really struggling to follow these steps, then let me know i can always upload the qvw.

5 Replies
Not applicable

I am doing a similar thing, but want to change the button label. I'm doing this with a Set Variable action and it works, but the problem is that the button keeps resizing to 39 width which is smaller than my text causing it to get squished up.

Is there a way to prevent the button from resizing?  If that's not possible, how about the ability to set the button size via variable?

Rick

buddhabang
Contributor III
Contributor III
Author

Helo Rick, try unticking the  "Allow Move/Size" box from the Layout Tab of the button you're working on.

This will ensure that button cannot be moved or resized. Hope this helps.

Not applicable

That only prevents an end user from dragging the size to a different size. What I really need is to be able to specify the width of say 90 and make the button stay 90 even if the label is only "One". A label of "One" is automatically resized down to something like (not in front of QV at the moment) 30. I want all of the buttons to be the same size regardless of the text displayed.

CELAMBARASAN
Partner - Champion
Partner - Champion

Hi buddhabang,

It can be simplified with single variable itself

On button1 click assign variable value as 1

On button click assign variable value as 2

then for changing colors

if(vButton=1, rgb(0,0,0), rgb(255,255,255))\\For button 1

if(vButton=2, rgb(0,0,0), rgb(255,255,255))\\For button 2


buddhabang
Contributor III
Contributor III
Author

Thanks Celambarasan, but wanted to make it clearer. But yeah it goes without saying.