pyside - How to elide a rich text after multiple lines in Qt? -
i trying elide rich text (with html type links) using qt , pyside. text strings this:
u"<a href='friend' style=\"text-decoration: none\">" \ u"<font color=#1abc9c>{}</font></a> agregó <a href='link' " \ u"style=\"text-decoration: none\"><font color=#1abc9c>{}</font></a>" \ u" su biblioteca".format(entitymocks.friendmock.display_name, entitymocks.assetmock1.title)
the documentation of qt explicitly states cannot done using rich text stripping text of html tags before passing qt´s elider. trying accomplish texts elide on multiple lines. test code 2 lines:
class doubleelidedtext(qlabel): def __init__(self, *args): super(doubleelidedtext, self).__init__(*args) def settext(self, text): self.settooltip(text) self.update() metrics = qfontmetrics(self.font()) elide = metrics.elidedtext(strip_tags(text), qt.elideright, self.width()*2 - self.width()/5) if metrics.width(elide) > self.width(): self.setminimumheight(metrics.height()*2) else: self.setminimumheight(metrics.height()) texto = u"{}".format(elide) super(doubleelidedtext, self).settext(texto) class mlstripper(htmlparser): def __init__(self): htmlparser.__init__(self) self.reset() self.fed = [] def handle_data(self, d): self.fed.append(d) def get_data(self): return ''.join(self.fed) def strip_tags(html): s = mlstripper() s.feed(html) return s.get_data()
this behavior (stripping html tags) has become unacceptable software.
i trying develop way elide rich text displayed in qlabel multiple lines. doing manually raises 1 particular issue not being able solve:
what length of displayed lines? (it depend on white space added @ end of every line).
am addressing issue correctly or there qtmagic missing in research?
Comments
Post a Comment