Results 1 to 6 of 6

Thread: QGraphicsTextItem Paint()

  1. #1
    Join Date
    Apr 2009
    Location
    China
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QGraphicsTextItem Paint()

    hello, I overrided the paint() in the class QGraphicsTextItem
    the Code
    Qt Code:
    1. void Tag::paint(QPainter *item,const QStyleOptionGraphicsItem *option,QWidget *widget)
    2. {
    3. QRectF rect = boundingRect();
    4. item->drawRect(rect);
    5. }
    To copy to clipboard, switch view to plain text mode 

    but the rect only display the top and left frame lines
    the bottom and right frame lines disappear

    thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsTextItem Paint()

    That's perfectly normal. Read QRect docs about the right() and bottom() members.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsTextItem Paint()

    Why is it perfeclty normal? The painter cannot draw it correctly?

    Isn't it a question of antialiasing?

  4. #4
    Join Date
    Apr 2009
    Location
    China
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsTextItem Paint()

    That's OK
    Qt Code:
    1. rect.setBottomRight(QPointF(rect.x() +100, rect.y()+100));
    To copy to clipboard, switch view to plain text mode 

    thanks a lot!

    I have another problem, how to change the line space?
    Last edited by goldhappywang; 18th September 2009 at 09:56.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsTextItem Paint()

    Quote Originally Posted by scascio View Post
    Why is it perfeclty normal? The painter cannot draw it correctly?

    Isn't it a question of antialiasing?
    It's a question of interpreting QRect. For historical reasons its bottom and right values are decreased by 1. Antialiasing is another thing but GV should compensate for it automatically.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    scascio (18th September 2009)

  7. #6
    Join Date
    Apr 2008
    Posts
    45
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsTextItem Paint()

    A box of height and width of 40 at 0,0 takes pixels 0-39 to draw. Now, if you draw a box that fits in that, and you measure, you'll get pixels 1-38 as the difference between the lines. This creates a problem, because your drawn with is no where near the 40 width your rect indicated. What you have to do is pic the next-highest pixel. So you end up drawing on 0 and 40. But the 40th pixel is clipped. I've seen this done in many different packages and it is "right".

Similar Threads

  1. Drawing standard widgets using a custom paint engine
    By Waywocket in forum Qt Programming
    Replies: 26
    Last Post: 21st October 2010, 20:40
  2. Problem on set QGraphicsTextItem write protect.
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2007, 20:53
  3. QGraphicsTextItem: handling cursor position change
    By Angelo Moriconi in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2007, 10:42
  4. QGraphicsTextItem size
    By Angelo Moriconi in forum Qt Programming
    Replies: 1
    Last Post: 26th January 2007, 08:34
  5. paint QTreeView item !!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2006, 14:24

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.