Results 1 to 3 of 3

Thread: QTextBrowser/QTextEdit html block width issue

  1. #1
    Join Date
    Jan 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QTextBrowser/QTextEdit html block width issue

    Hi folks,

    I observe an issue with the rendering of html block elements (with Qt 4.5.3 & 4.6.1 / WinXP):


    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 ?

    Qt Code:
    1. // _doc is a QTextDocument*;
    2. QTextFrame* root= _doc->rootFrame();
    3.  
    4. QTextCursor c= root->firstCursorPosition();
    5.  
    6. c.insertHtml("<div align=\"center\"><h1>Title.</h1></div><br>");
    7. c.insertBlock();
    8. c.insertHtml("<div align=\"center\"><h1>Title 2.</h1></div>");
    9.  
    10. QTextFrameFormat providerFrame;
    11. providerFrame.setBorder( 1.0);
    12. providerFrame.setWidth(200.0);
    13.  
    14. QTextFrame* f1= c.insertFrame(providerFrame);
    15. c.insertHtml("<h2>Frame #1 header.</h2><br>"
    16. "<p>content 1</p>"
    17. "<p>content 2</p>");
    18.  
    19. c= root->lastCursorPosition();
    20. c.insertBlock();
    21.  
    22. QTextFrame* f2= c.insertFrame(providerFrame);
    23. c.insertHtml("<br><h2>Frame #2 header.</h2>"
    24. "<p>content 1</p>"
    25. "<p>content 2</p>");
    26.  
    27. c= root->lastCursorPosition();
    28. c.insertHtml("<p>end</p>");
    To copy to clipboard, switch view to plain text mode 
    H2 css:
    Qt Code:
    1. h2 { font-size: 120%; font-weight: bold; background: lightgray; }
    To copy to clipboard, switch view to plain text mode 

    >This< seems to be a related post, but unfortunately not solved

    Regards,
    lexar
    Attached Images Attached Images

  2. #2
    Join Date
    Sep 2009
    Posts
    72
    Thanked 10 Times in 10 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: QTextBrowser/QTextEdit html block width issue

    Hi

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

  3. #3
    Join Date
    Jan 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextBrowser/QTextEdit html block width issue

    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...

Similar Threads

  1. QTextBrowser and html
    By iamjayanth in forum Newbie
    Replies: 2
    Last Post: 6th July 2009, 16:49
  2. Text block centering in Qt4.4 QTextEdit
    By mla1290 in forum Qt Programming
    Replies: 3
    Last Post: 10th July 2008, 18:46
  3. GIF or MNG images for use in html for QTextBrowser
    By manojmka in forum Qt Programming
    Replies: 3
    Last Post: 2nd January 2008, 17:30
  4. Loading images in html in a QTextBrowser
    By BasicPoke in forum Newbie
    Replies: 1
    Last Post: 6th June 2007, 22:51
  5. QTextBrowser, html & pictures
    By jey in forum Qt Programming
    Replies: 3
    Last Post: 20th March 2006, 08:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.