Switch 8: Square-corner track switch
This switch swaps the round pill for a rectangular track with softened corners, and uses a rectangle as the knob. It suits structured, grid-like dashboards.
This preview demonstrates the appearance only and is not connected to a live Qlik app. In Qlik, a separate button action must change vSwitch between 0 and 1.
The Qlik expression
Paste into a measure displayed as an image.
='data:image/svg+xml;utf8,' &
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 90 50" width="100%" height="100%" preserveAspectRatio="xMidYMid meet">' &
'<rect x="8" y="4" width="72" height="42" rx="11" fill="' & If($(vSwitch)=1,'%234052c5','%23e7eaf2') & '" stroke="%23d7dae1" stroke-width="2">' &
'<animate attributeName="fill" from="' & If($(vSwitch)=1,'%23e7eaf2','%234052c5') & '" to="' & If($(vSwitch)=1,'%234052c5','%23e7eaf2') & '" dur="0.2s" fill="freeze"/>' &
'</rect>' &
'<rect x="' & If($(vSwitch)=1,'38','13') & '" y="4" width="38" height="42" rx="8" fill="%23ffffff" stroke="%23c5c7cb" stroke-width="2.5">' &
'<animate attributeName="x" from="' & If($(vSwitch)=1,'13','38') & '" to="' & If($(vSwitch)=1,'38','13') & '" dur="0.2s" fill="freeze"/>' &
'</rect>' &
'</svg>'How the expression works
- 1
Data URI and viewBox
'data:image/svg+xml;utf8,' & '<svg ... viewBox="0 0 90 50" ...>'Inline SVG on a 90×50 grid that scales to fit the Qlik object.
- 2
Corner radius
<rect x="8" y="4" width="72" height="42" rx="11" ...>rx=11 is about a quarter of the height, so corners are softened rather than fully round.
- 3
Conditional track colour
If($(vSwitch)=1,'%234052c5','%23e7eaf2')Blue when vSwitch is 1, pale grey when 0. # is written as %23 so the data URI stays valid.
- 4
Softened square knob
<rect ... y="4" width="38" height="42" rx="8" fill="%23ffffff">A white rectangle with rx=8 — slightly tighter than the track so it nests neatly.
- 5
Conditional knob position
x="' & If($(vSwitch)=1,'38','13') & '"Rectangles are placed by their left edge, x. 38 when ON (right), 13 when OFF (left).
- 6
Optional animation
<animate attributeName="x" ... dur="0.2s" fill="freeze"/>Animates x so the knob slides between positions.
Qlik setup
Done in your Qlik app, separate from the preview above. vSwitch must be 0 (OFF) or 1 (ON).
1. Create the variable
In edit mode, open Variables and create vSwitch starting at 0.
Name: vSwitch
Definition: 02. Add a button action
Button → Set variable value → vSwitch, with this value.
=1-$(vSwitch)3. Place the expression in an object that renders images (e.g. a Text & image measure shown as an image), next to or under the button.
Troubleshooting
The knob overlaps the track edge+
Keep the knob's y and height equal to the track's (4 and 42) and x between 13 and 38.
The image is broken or blank+
Check every colour uses %23 instead of #, quotes are balanced, and the measure is shown as an image.
The switch never changes+
The SVG only draws the state. Confirm vSwitch is 0 or 1 and that a separate Qlik button action toggles it with =1-$(vSwitch).