Results 1 to 3 of 3

Thread: Setting margin for drawText

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Setting margin for drawText

    I have a custom item delegate to color tableview rows.
    It works fine with one exception - the text is drawn with no margin.
    The standard delegate sets a small margin to the left of the text it draws.
    I have looked at the Trolls source for the standard delegate but with my limited skills, I can't see how to achieve this in my code.
    This is the line that draws the text:

    painter->drawText(option.rect, Qt::AlignJustify, index.data().toString());

    Any ideas are appreciated....

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Setting margin for drawText

    Change option.rect

    It's a rectangle that defines the place where the text is drawn. Just shift it a few pixels.

  3. The following user says thank you to tbscope for this useful post:

    waynew (6th September 2010)

  4. #3
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting margin for drawText

    Thanks tbscope - it's perfect now.

    Qt Code:
    1. QRect rect = option.rect;
    2. rect = rect.adjusted(3, 0, 0, 0);
    3. painter->drawText(rect, Qt::AlignJustify, index.data().toString());
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QPainter.drawText and margin/padding
    By invictus in forum Newbie
    Replies: 1
    Last Post: 24th July 2009, 12:56
  2. QTableView and margin
    By miraks in forum Qt Programming
    Replies: 6
    Last Post: 17th May 2009, 15:14
  3. Setting layout margin and spacing globally
    By aarpon in forum Qt Programming
    Replies: 0
    Last Post: 7th April 2009, 12:23
  4. zero'ing margin in a qhboxlayout
    By illuzioner in forum Qt Programming
    Replies: 3
    Last Post: 2nd July 2007, 10:54
  5. How to Set margin
    By suresh in forum Newbie
    Replies: 1
    Last Post: 5th October 2006, 06:13

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.