Instead of using a traditional checkbox, I'd like to display my options using a more human-readable format. To show exactly what I want, I have implemented it in a language I'm very familiar with.
Would it be possible to recreate the following example using Qt? If so, I would like some pointers on how to do it, it's not obvious to me how to do this in a non-hacky fashion.
var $ = document.querySelector.bind(document);
var toggle = $('.toggle');
var first = toggle.firstChild;
var last = toggle.lastChild;
last.style.display = "none";
function hide(el) {
el.style.display = "none";
}
function show(el) {
el.style.display = "inherit";
}
var current = false;
toggle.addEventListener("click", function () {
current = !current;
if (!current) {
hide(last);
show(first);
} else {
show(last);
hide(first);
}
});
span.toggle {
border-bottom: 1px dashed;
}
span.toggle:hover {
cursor: pointer;
}
<p class="example">I will start <span class="toggle"><span>minimized</span><span>maximized</span></span>!</p>
You can achieve this by connecting to the
linkActivated
signal of aQLabel
. AQLabel
can contain rich text, like URLs, which when clicked, emit thelinkActivated
signal. A minimal example is included below.In this example we create a
QLabel
with some rich text containing an anchor around the clickable text (I've called the anchor#toggle
but it could be anything). When clicked, it triggers thelinkclicked
method which changes the text based on the anchor. So we swap between two anchors,#toggle
and#toggle2
, while also changing the text.This is obviously a minimal example. You could store the current state in a boolean variable and toggle the text based on that (without needing multiple anchor names) or all sort of other things! Hopefully this gives you a basic idea which you can expand upon.