Results 1 to 1 of 1

Thread: QTextEdit and QPlainTextEdit Wrapping

  1. #1
    Join Date
    Jun 2014
    Posts
    20
    Thanks
    2

    Unhappy QTextEdit and QPlainTextEdit Wrapping

    Hello,

    someone knows how these two widgets do paragraph warpping? e.g 25 characters one line.

    The goal is to specify a certain block's line length, not the whole document.

    e.g

    Qt Code:
    1. im paragraph 1 im paragraph 1 im paragraph 1 im paragraph 1 im paragraph 1
    2.  
    3. im paragraph 2
    4. im paragraph 2
    5. im paragraph 2
    6. im paragraph 2
    To copy to clipboard, switch view to plain text mode 

    it could be achieved by adding paragraphbreak at the end of divided lines (so simple)
    but i wonder whether i could do it without the hack, because adding break turns the paragraph 2 into 3 4 5...


    issue update:

    a seemingly working solution after some digging:

    Qt Code:
    1. // textLayout inherits QPlainTextDocumentLayout
    2.  
    3. QRectF textLayout :: blockBoundingRect(const QTextBlock& block) const
    4. {
    5. // check whether the block is target block need to be wrapped
    6. // ...
    7. // line width in pixel
    8.  
    9. if (...) {
    10. QTextLayout* layout = block.layout();
    11. layout->clearLayout();
    12.  
    13. qreal height = 0;
    14. layout->beginLayout();
    15.  
    16. while (true) {
    17. QTextLine line = layout->createLine();
    18. if (! line.isValid())
    19. break;
    20.  
    21. line.setLineWidth(lineWidth);
    22. line.setPosition(QPointF(0, height));
    23. height += line.height();
    24. }
    25. layout->endLayout();
    26. }
    27.  
    28. return QPlainTextDocumentLayout::blockBoundingRect(block);
    29. }
    To copy to clipboard, switch view to plain text mode 

    The text is fine wrapped at the paragraph, but ... scrollbar never comes, what's more, it only works under WidgetWrap Mode.

    so the new issues extended:

    how to make the scrollbar come?
    Last edited by cic1988; 26th June 2014 at 11:07.

Similar Threads

  1. QPlainTextEdit Wrapping
    By cic in forum Qt Programming
    Replies: 1
    Last Post: 26th February 2014, 11:54
  2. Replies: 1
    Last Post: 3rd December 2013, 19:59
  3. Replies: 7
    Last Post: 4th February 2013, 14:58
  4. margins in QTextEdit/QPlainTextEdit
    By corrado in forum Qt Programming
    Replies: 2
    Last Post: 22nd April 2010, 10:35
  5. Maximum input length for QTextEdit or QPlainTextEdit ??
    By b_ginner in forum Qt Programming
    Replies: 2
    Last Post: 22nd August 2009, 21:57

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
  •  
Qt is a trademark of The Qt Company.