Results 1 to 3 of 3

Thread: QPainter::drawRect(QRect) suspect height behaviour

  1. #1
    Join Date
    Nov 2014
    Location
    Germany
    Posts
    69
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default QPainter::drawRect(QRect) suspect height behaviour

    Hi,

    in my QTableWidgetItems, I try to display a list of (3) strings vertically ordered and with a border.

    For this border, I'd like to draw the rect in a loop and change its y-coordinate, so the same rect should be painted vertically shifted.

    This is my code:
    Qt Code:
    1. rectStringEvent.setY(rectCell.y() + 20); // position of the first string
    2. rectStringEvent.setHeight(15); // rect height, should not be changed but it does!
    3.  
    4. for(int i = 0; i < 3; i++)
    5. {
    6. pPainter->drawText(rectStringEvent, listEvents.at(i));
    7. pPainter->drawRect(rectStringEvent);
    8. rectStringEvent.setY(rectStringEvent.y() + 15); // <--- this line is the problem: it also changes the rects height! But why?
    9. }
    To copy to clipboard, switch view to plain text mode 
    I figured out that the rect's height is decreased by the number I increase the y-coordinate. I don't understand this behaviour. Why can't I just change the y-coordinate and the rect moves and still has it's prior height?

    Thank you in anticipation.
    Binary

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPainter::drawRect(QRect) suspect height behaviour

    You are changing the y-coordinate of the top corners, keeping the bottom corners where they are. So the height shrinks.

    What you are looking for is QRect::moveTop().

    Cheers,
    _

  3. #3
    Join Date
    Nov 2014
    Location
    Germany
    Posts
    69
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: QPainter::drawRect(QRect) suspect height behaviour

    Yes, you're right. Thank you, it works.

    Greetings

Similar Threads

  1. QPainter::drawEllipse and QTransform strange behaviour
    By webstar2568 in forum Qt Programming
    Replies: 0
    Last Post: 8th March 2011, 14:57
  2. Replies: 1
    Last Post: 3rd October 2010, 18:41
  3. Replies: 6
    Last Post: 15th April 2010, 19:56
  4. Strange behaviour with QPainter
    By franco.amato in forum Qt Programming
    Replies: 12
    Last Post: 14th January 2010, 05:30
  5. Strange behaviour of QPainter...
    By oscar in forum Qt Programming
    Replies: 2
    Last Post: 8th November 2008, 12:07

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.