Results 1 to 6 of 6

Thread: What is the difference between QRect and QRectF?

  1. #1
    Join Date
    Jul 2014
    Posts
    95
    Thanks
    67

    Default What is the difference between QRect and QRectF?

    Hello,What is the difference between QRect and QRectF? The following code work well. It is interesting.
    Qt Code:
    1. #include "lines.h"
    2. #include <QPainter>
    3.  
    4.  
    5. Lines::Lines(QWidget *parent)
    6. : QWidget(parent)
    7. {
    8.  
    9. }
    10.  
    11. void Lines::paintEvent(QPaintEvent *e)
    12. {
    13. Q_UNUSED(e);
    14. QPainter qp(this);
    15. drawLines(&qp);
    16. }
    17.  
    18. void Lines::drawLines(QPainter *qp)
    19. {
    20.  
    21. QRect rect(100.5,100.5,200.2,200.3);
    22. qp->drawRect(rect);
    23. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: What is the difference between QRect and QRectF?

    What is the difference between QRect and QRectF ?
    Qt Code:
    1. The QRectF class defines a rectangle in the plane using floating point precision...
    2. ...
    3. The QRect class defines a rectangle in the plane using integer precision...
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QRect rect(100.5,100.5,200.2,200.3);
    To copy to clipboard, switch view to plain text mode 
    Double values are implicitly converted to integers. You can find detailed info here: Type Conversions

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

    rezas1000 (10th September 2014)

  4. #3
    Join Date
    Jul 2014
    Posts
    95
    Thanks
    67

    Default Re: What is the difference between QRect and QRectF?

    I understand,But if the double value converted to integer,why the QRect and the QRectF were built? please explain,thank you.

  5. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: What is the difference between QRect and QRectF?

    Check the link mentioned by stampede, all you need is there.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

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

    rezas1000 (11th September 2014)

  7. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: What is the difference between QRect and QRectF?

    if the double value converted to integer,why the QRect and the QRectF were built?
    Exactly the same reason you have integers and doubles, sometimes you want one, sometimes the other

  8. The following user says thank you to stampede for this useful post:

    rezas1000 (11th September 2014)

  9. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: What is the difference between QRect and QRectF?

    why the QRect and the QRectF were built? please explain,thank you.
    With Qt 4, the coordinate system used in painting was changed from integer-based (pixels) to floating point (world coordinates). This permitted scaling and other transformations to be specified and performed more precisely, without rounding errors. In order to not break all existing code, a new set of floating point coordinate classes (QRectF, QSizeF, QPointF, etc.) was introduced side-by-side with the integer versions, and painting operations were extended to use the new floating point classes without changing the pre-existing integer methods.

  10. The following user says thank you to d_stranz for this useful post:

    rezas1000 (11th September 2014)

Similar Threads

  1. Implementation differences between QRect and QRectF
    By wayfaerer in forum Qt Programming
    Replies: 1
    Last Post: 30th December 2012, 10:59
  2. Resize QRectF in drawText when necessary
    By estanisgeyer in forum Qt Programming
    Replies: 0
    Last Post: 21st February 2010, 14:27
  3. difference of QRect and QRectF
    By gbmtoday in forum Newbie
    Replies: 1
    Last Post: 14th January 2010, 22:52
  4. Rotate a QRectF
    By whitefurrows in forum Qt Programming
    Replies: 5
    Last Post: 15th July 2009, 15:33
  5. QRectF and drawText
    By aronsson in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2006, 16:05

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.