Results 1 to 2 of 2

Thread: HTML text drawn with QPainter::drawText()

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default HTML text drawn with QPainter::drawText()

    Hi to all!

    I have following situation: I have a merchandize description field in my database. This field's contens is HTML based text and I would like to draw it via QPaint::drawText(). Is this possible, and if it is, is HTML formatting smart to do inside paintEvent()?
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    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: HTML text drawn with QPainter::drawText()

    Is same as Print , have a look on... :
    http://www.qt-apps.org/content/show....?content=62383

    Qt Code:
    1. ///// inside QWidget Hover Label
    2. QString text_x = "Hello World!";
    3. doc = new QTextDocument(this);
    4. doc->setUndoRedoEnabled(false);
    5. doc->setHtml("<p><span style=\"color:#000000; font-weight:600\">"+text_x+"</span></p>");
    6. doc->setTextWidth(width());
    7. doc->setUseDesignMetrics(true);
    8. doc->setDefaultTextOption ( QTextOption (Qt::AlignHCenter ) );
    9. //// height from doc QTextDocument
    10. //// http://fop-miniscribus.googlecode.com/svn/trunk/fop_miniscribus.1.0.0/src/floating_box/floatdiagram.cpp
    11. //////setMaximumHeight(DocumentHighgtActual());
    12.  
    13. QPainter *p = new QPainter(&PicsDocument);
    14. p->setRenderHint(QPainter::Antialiasing, true);
    15. doc->drawContents(p,clip);
    16. p->end();
    17.  
    18. ///// QPixmap PicsDocument contains image as html
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. QPushButton and HTML text
    By ivan.cukic in forum Qt Programming
    Replies: 2
    Last Post: 20th March 2007, 13:48
  3. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30

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.