Results 1 to 3 of 3

Thread: Draw some characters of string in bold - QAbstractItemDelegate - QPainter

  1. #1
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Draw some characters of string in bold - QAbstractItemDelegate - QPainter

    I'm using painter->drawTex() to draw text on the qlistview, but how can I make some of the string's characters be drawn in bold?
    I did think about drawing each character separatly, but I can't get the width of the drawn character, and a fixed width would not be portable.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Draw some characters of string in bold - QAbstractItemDelegate - QPainter

    You have to use QFontMetrics to determine the width of characters or strings.

    To have a more easy approach you can use QTextDocument which accepts HTML and then render the document to your painter using QTextDocument::drawContents().

  3. #3
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Draw some characters of string in bold - QAbstractItemDelegate - QPainter

    Ok, it seems like it would work, but for some reason the string is writen only on first row and only when scrolling up...

    Qt Code:
    1. painter->setPen(QColor("black"));
    2. painter->setFont(QFont("Arial",11,QFont::AllLowercase));
    3. //painter->drawText(QPoint(option.rect.x() + 50, option.rect.y() + 20), o->name()); // this renders perfectly in place
    4.  
    5. doc->setHtml(o->name());
    6. doc->drawContents(painter,QRect(option.rect.x() + 50,
    7. option.rect.y(), // if I use + 20, the text is never rendered, not even in first row..
    8. option.rect.width(),
    9. 30));
    To copy to clipboard, switch view to plain text mode 

    My problem is similar to http://www.qtforum.org/article/37784...istwidget.html, and that never got resolved.

Similar Threads

  1. How does one draw a 'cut down' ellipse using QPainter
    By Eos Pengwern in forum Qt Programming
    Replies: 3
    Last Post: 24th July 2012, 02:01
  2. how to draw points with qpainter?
    By athulms in forum Newbie
    Replies: 4
    Last Post: 23rd August 2011, 09:10
  3. Qt for S60, problem with bold polish characters
    By Wiktor in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 26th August 2009, 10:37
  4. Replies: 5
    Last Post: 10th January 2008, 14:26
  5. inserting string > 127 characters to MS Access
    By jh in forum Qt Programming
    Replies: 0
    Last Post: 12th May 2006, 18:11

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.