Qt-interest Archive, February 2007
Richtext: multiple appends vs. style='white-space:pre'
Message 1 in thread
Hello everyone,
Let's say I have two lines of text, and I want to forbid line breaking
in the first one. Rich text for this would be:
<p style='white-space:pre'>this is a test of line wrapping</p>
<p>this line is longer, and I expect it to wrap, even if the first line
was not wrapped</p>
Now I want to add this to a newly created QTextEdit instance, which is
too narrow to display the first line without a scrollbar.
If I use setText() or one append(), everything works as expected.
However, if I use two append() calls, one for each <p>, then the second
paragraph is not wrapped, too.
Could anyone tell me what's going on and how can I prevent this? Thanks
in advance.
Simple test application:
#include <QApplication>
#include <QTextEdit>
int main(int argc, char** argv)
{
QApplication a(argc,argv);
QTextEdit te;
te.resize(100,100);
te.setWordWrapMode(QTextOption::WordWrap);
// working version:
te.append("<p style='white-space:pre'>this is a test of line
wrapping</p><p>this line is longer, and I expect it to wrap, even if the
first line was not wrapped</p>");
// not-working alternative, commented out:
//te.append("<p style='white-space:pre'>this is a test of line
wrapping</p>");
//te.append("<p>this line is longer, and I expect it to wrap, even if
the first line was not wrapped</p>");
// end
te.show();
return a.exec();
}
--
[ signature omitted ]