Workaround for QStaticText not rendering <h2> correctly in Qt 6.7.2

This commit is contained in:
Kovid Goyal 2024-07-18 09:08:25 +05:30
parent 6bff175993
commit 5505bb537a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -599,18 +599,18 @@ class Delegate(QStyledItemDelegate):
bottom = option.rect.bottom() - 2 bottom = option.rect.bottom() - 2
painter.drawLine(0, bottom, option.rect.right(), bottom) painter.drawLine(0, bottom, option.rect.right(), bottom)
if 'static-text' not in theme: if 'static-text' not in theme:
from xml.sax.saxutils import escape
visit = _('Right click to visit theme homepage') if theme.get('url') else '' visit = _('Right click to visit theme homepage') if theme.get('url') else ''
theme['static-text'] = QStaticText(_( theme['static-text'] = QStaticText(_('''\
''' <p><b>{title}</b><p>
<h2>{title}</h2>
<p>by <i>{author}</i> with <b>{number}</b> icons [{size}]</p> <p>by <i>{author}</i> with <b>{number}</b> icons [{size}]</p>
<p>{description}</p> <p>{description}</p>
<p>Version: {version} Number of users: {usage:n}</p> <p>Version: {version} Number of users: {usage:n}</p>
<p><i>{visit}</i></p> <p><i>{visit}</i></p>
''').format(title=theme.get('title', _('Unknown')), author=theme.get('author', _('Unknown')), ''').format(title=escape(theme.get('title') or _('Unknown')), author=escape(theme.get('author', _('Unknown'))),
number=theme.get('number', 0), description=theme.get('description', ''), number=theme.get('number', 0), description=escape(theme.get('description', '')),
size=human_readable(theme.get('compressed-size', 0)), version=theme.get('version', 1), size=human_readable(theme.get('compressed-size', 0)), version=theme.get('version', 1),
usage=theme.get('usage', 0), visit=visit usage=theme.get('usage', 0), visit=escape(visit)
)) ))
painter.drawStaticText(COVER_SIZE[0] + self.SPACING, option.rect.top() + self.SPACING, theme['static-text']) painter.drawStaticText(COVER_SIZE[0] + self.SPACING, option.rect.top() + self.SPACING, theme['static-text'])
painter.restore() painter.restore()
@ -1000,8 +1000,8 @@ def install_icon_theme(theme, f, rcc_path, for_theme):
if __name__ == '__main__': if __name__ == '__main__':
from calibre.gui2 import Application from calibre.gui2 import Application
app = Application([]) app = Application([])
create_theme(sys.argv[-1]) # create_theme(sys.argv[-1])
# d = ChooseTheme() d = ChooseTheme()
# if d.exec() == QDialog.DialogCode.Accepted and d.commit_changes is not None: if d.exec() == QDialog.DialogCode.Accepted and d.commit_changes is not None:
# d.commit_changes() d.commit_changes()
del app del app