Results 1 to 4 of 4

Thread: Rich text in QGraphicsTextItem

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Rich text in QGraphicsTextItem

    Hi guys,

    I have my items(derived from QGraphicsTextItem. These items are children of other items. I enter some text in QtextEdit and use the text document from the textEdit to set text to my text items. Still, when setting the textDocument for the textItem I only get plain text. I also tried settings HTML for my items, but still I only see plain text.
    Any idea, why I can't display a rich text in QGraphicsTextItem?


    Thanks,

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Rich text in QGraphicsTextItem

    What does the subclass do? It works with plain QGraphicsTextItem.
    J-P Nurmi

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Rich text in QGraphicsTextItem

    try to clone document
    QTextDocument * QTextDocument::clone ( QObject * parent = 0 ) const
    and after insert on QGraphicsTextItem

    void QGraphicsTextItem::setDocument ( QTextDocument * document )

    at end only document()->setPageSize ( docoriginal->pageSize() )
    to fit on size...

    if not run display your code section.

    or try to build
    http://code.google.com/p/fop-miniscribus/ screenshot bottom
    it edit QTextDocument inside QGraphicsRectItem each page.
    the base is http://fop-miniscribus.googlecode.co...nk/QTextPanel/

  4. #4
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Rich text in QGraphicsTextItem

    Hi,

    Thanks for the explanation; I tried most of the ideas, but did not set 'pagesize'. I will set pagesize and see if it helps.

    {edited} ok, I solved the problem;
    [SOLVED]

    THanks,

    Kacper


    [EDITED]
    The ideas are good, but are not working in my code.
    Piece of my code
    Qt Code:
    1. ...//_doc is QTextEdit->document();
    2. // When I qDebug()<<_doc it shows multiple lines
    3. // when setting on item the text is only one line.
    4. // I simply need multiple lines of text ( Max 5 lines 20 char each, etc)
    5. void MyItem::vUpdateText(QTextDocument* _doc)
    6. {
    7. m_textDoc = _doc->clone();
    8. setDocument(m_textDoc);
    9. document()->setPageSize(_doc->pageSize());
    10. update(boundingRect());
    11. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by maverick_pol; 29th September 2008 at 20:48. Reason: code still not working
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Rich text with QPainter?
    By sarefo in forum Qt Programming
    Replies: 3
    Last Post: 7th April 2008, 14:40
  3. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 16:45
  4. Replies: 3
    Last Post: 13th December 2007, 16:10
  5. Rich Text Format
    By Kapil in forum Newbie
    Replies: 1
    Last Post: 4th October 2006, 10:53

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.