[Interest] QTextDocument supports tabstops, but can't insert tabs via html?
Josh
jnfo-d at grauman.com
Wed May 20 00:59:34 CEST 2020
Hi all,
QTextDocument supports tab stops. For example QTextOption has setTabs()
and so you can call QTextDocument::setDefaultTextOption() and also
QTextBlockFormat has setTabPositions().
Obviously html doesn't support tabs and as multiple whitespaces are just
ignored.
But is there any way for tabs to be inserted via QTextCursor::insertHtml()
and/or QTextDocument::setHtml()?
There are features of QTextDocument that are hard to access without
insertHtml, but this is one feature that as far as I can tell is only
accessible via QTextCursor::insertText() and
QTextDocument::setPlainText().
I've been able to mix/match insertHtml() and insertText() to split up my
insertHtml() calls and insert tabs with insertText(). It sort of works
(see below), but I'm checking if there is a better solution...
Thanks,
Josh
QStringList tabText = text.split("\t");
text="";
for(int i=0; i<tabText.size(); i++)
{
myCursor->insertHtml(QString("<span style='%2'>%1</span>").arg(tabText[i]).arg(effect));
if(i<tabText.size()-1)
myCursor->insertText("\t");
}
More information about the Interest
mailing list