PDA

View Full Version : QTextBrowser/QTextEdit html block width issue



lexar
26th January 2010, 10:39
Hi folks,

I observe an issue with the rendering of html block elements (with Qt 4.5.3 & 4.6.1 / WinXP):
http://www.qtcentre.org/attachment.php?attachmentid=4198

1. The "Title" 1&2 formats differ only by the appended '<br>' tag, and without it the center alignment is not working. What is wrong here ? How can this be fixed without this extra tag ? (insertBlock() won't help)

2. But this hack does not work for in frame html any more. As you can see in the code for H2 "Frame #1/2 header". Here the '<br>' tag positioned in front makes the hack ?!?

So what do I the wrong way? How is the correct way to declare a frame-wide html block without some hooks ?



// _doc is a QTextDocument*;
QTextFrame* root= _doc->rootFrame();

QTextCursor c= root->firstCursorPosition();

c.insertHtml("<div align=\"center\"><h1>Title.</h1></div><br>");
c.insertBlock();
c.insertHtml("<div align=\"center\"><h1>Title 2.</h1></div>");

QTextFrameFormat providerFrame;
providerFrame.setBorder( 1.0);
providerFrame.setWidth(200.0);

QTextFrame* f1= c.insertFrame(providerFrame);
c.insertHtml("<h2>Frame #1 header.</h2><br>"
"<p>content 1</p>"
"<p>content 2</p>");

c= root->lastCursorPosition();
c.insertBlock();

QTextFrame* f2= c.insertFrame(providerFrame);
c.insertHtml("<br><h2>Frame #2 header.</h2>"
"<p>content 1</p>"
"<p>content 2</p>");

c= root->lastCursorPosition();
c.insertHtml("<p>end</p>");

H2 css:
h2 { font-size: 120%; font-weight: bold; background: lightgray; }

>This< (http://www.qtcentre.org/threads/16599-QTextCursor-insertHtml%28%29-questions) seems to be a related post, but unfortunately not solved :(

Regards,
lexar

vishwajeet.dusane
26th January 2010, 12:52
Hi

I am not sure this will help you but why dn't you try QWebView class for setting up html data ?

lexar
26th January 2010, 13:47
I don't need the full power of a web renderer. And tried the text-browser first in hope it will consume fewer resources...

Seems that the insertHtml()/html-rendering functionality is definitely broken. Have found additional positioning/layout issues in between. Hope Qt will document the engine constraints and fix the bugs, some day...