pyside - Creating a toggleable text widget in qt -


instead of using traditional checkbox, i'd display options using more human-readable format. show want, have implemented in language i'm familiar with.

would possible recreate following example using qt? if so, pointers on how it, it's not obvious me how in 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 start <span class="toggle"><span>minimized</span><span>maximized</span></span>!</p>

you can achieve connecting linkactivated signal of qlabel. qlabel can contain rich text, urls, when clicked, emit linkactivated signal. minimal example included below.

in example create qlabel rich text containing anchor around clickable text (i've called anchor #toggle anything). when clicked, triggers linkclicked method changes text based on anchor. swap between 2 anchors, #toggle , #toggle2, while changing text.

from pyside import qtgui, qtcore import sys  app = qtgui.qapplication(sys.argv) win = qtgui.qmainwindow() label = qtgui.qlabel('i start <a href="#toggle">minimized</a>!') def linkclicked(url):     if url == '#toggle':         label.settext('i start <a href="#toggle2">maximized</a>!')     else:                 label.settext('i start <a href="#toggle">minimized</a>!')  label.linkactivated.connect(linkclicked) win.setcentralwidget(label) win.show() sys.exit(app.exec_()) 

this minimal example. store current state in boolean variable , toggle text based on (without needing multiple anchor names) or sort of other things! gives basic idea can expand upon.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -