Results 1 to 8 of 8

Thread: Split single QTextEdit into several QGraphicsProxyWidget

  1. #1
    Join Date
    Jul 2015
    Posts
    22
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Split single QTextEdit into several QGraphicsProxyWidget

    I'm developing a text editor which shows pages in LibreOffice's manner (e.g. on solid background with space between pages).

    So, there is one sample of QTextDocument and several samples of QTextEdit (depending on page count) scrolled to certain page with QTextEdit::verticalScrollBar()->setValue(int). I place each QTextEdit on QGraphicsScene with QGraphicsProxyWidget.

    Is that manner of QTextDocument handling redundant? Is there way to place one QTextEdit on several QGraphicsProxyWidgets (one page on each proxy widget)? E.g. if document has one page then one proxy widget occurs, if it has two pages then QTextEdit gets longer instead of scrolling and second page's content appears on second page and so on. Or my solution is only way due to limitations that Qt makes?

    I have found this post but due to expiring of source code attached in one of its replies I can't be sure that this is definitely that I need.
    Last edited by Toniy; 6th March 2017 at 16:11.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Split single QTextEdit into several QGraphicsProxyWidget

    That doesn't sound like a good use case for a widget in a graphics item proxy.

    I would recommend investigating how QTextEdit draws part of the text and then implement your page items that work on the same QTextDocument, each drawing "its" page.

    Cheers,
    _

  3. #3
    Join Date
    Jul 2015
    Posts
    22
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Split single QTextEdit into several QGraphicsProxyWidget

    Thanks for reply.

    You mean to implement my own QTextEdit-like widget without scrolling, don't you?

    That doesn't sound like a good use case for a widget in a graphics item proxy
    For better understanding of situation: what certainly isn't good in that use case?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Split single QTextEdit into several QGraphicsProxyWidget

    Quote Originally Posted by Toniy View Post
    You mean to implement my own QTextEdit-like widget without scrolling, don't you?
    My interpretation of your goal is that you want the graphicsview to be the scrollable area, with one item per page of the document.
    So you wouldn't need a widget at all (that's the graphicsview), but "page" items to put into the view's scene.

    Quote Originally Posted by Toniy View Post
    For better understanding of situation: what certainly isn't good in that use case?
    These are bascially hacks to take an existing widget into a graphicsscene, e.g. buttons or comboboxes.
    Widgets weren't designed to be embedded into such a situation, the proxy tries its best but sometimes things don't work that well.

    Wouldn't use it for a complex control such as a text edit unless absolutely necessary.

    Cheers,
    _

  5. #5
    Join Date
    Jul 2015
    Posts
    22
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Split single QTextEdit into several QGraphicsProxyWidget

    but "page" items to put into the view's scene
    So, it is sufficient for my "page" item to be a subclass of QGraphicsItem, isn't it?
    If so then next question occurs: do I understand correct that all low-level text editing functions like placing text on page, keeping line spacings, painting tables and so on must be implemented by me?

    Explanation for proxy widget is undestood, thanks.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Split single QTextEdit into several QGraphicsProxyWidget

    Quote Originally Posted by Toniy View Post
    So, it is sufficient for my "page" item to be a subclass of QGraphicsItem, isn't it?
    Yes, that would be my guess

    Quote Originally Posted by Toniy View Post
    If so then next question occurs: do I understand correct that all low-level text editing functions like placing text on page, keeping line spacings, painting tables and so on must be implemented by me?
    Well, text model modification and rendering can likely be delegated to QTextDocument, like QTextEdit would do itself.
    You'll have to do the input handling of course.

    Might also be worth to look into how other Qt based page oriented editing applications handle this, e.g. Calligra Words or Stage: https://cgit.kde.org/calligra.git/tree/

    Cheers,
    _

  7. The following user says thank you to anda_skoa for this useful post:

    Toniy (16th March 2017)

  8. #7
    Join Date
    Jul 2015
    Posts
    22
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Split single QTextEdit into several QGraphicsProxyWidget

    Thanks for replies, direction of thinking becomes much more clear.

    You'll have to do the input handling of course.
    Do I understand correct that input handling (besides scrolling) is only thing that QTextEdit does on its own?
    Last edited by Toniy; 13th March 2017 at 14:19. Reason: spelling corrections

  9. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Split single QTextEdit into several QGraphicsProxyWidget

    You'll have to look at the code.
    Either locally or through the great code browser at Woboq.org

    Cheers,
    _

Similar Threads

  1. Replies: 7
    Last Post: 6th February 2017, 20:10
  2. [QTextEdit] Delete single lines
    By bmn in forum Qt Programming
    Replies: 3
    Last Post: 18th July 2012, 17:57
  3. split QByteArray
    By xproch13 in forum Newbie
    Replies: 2
    Last Post: 29th October 2010, 22:50
  4. Single line QTextEdit
    By Arthur in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2010, 22:04
  5. how to split a class ?
    By mimmo_kallon in forum Newbie
    Replies: 0
    Last Post: 8th April 2008, 12:37

Tags for this Thread

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.