0

Does anyone know why QRectF right()/bottom() methods behaves differently than QRect ?

The following example

QRectF r1(0, 0, 20, 20);
qDebug() << r1.right();

QRect r2(0, 0, 20, 20);
qDebug() << r2.right();

returns this result:

20
19

When I tried to measure width(), both returns 20

QRectF r1(0, 0, 20, 20);
qDebug() << r1.width();

QRect r2(0, 0, 20, 20);
qDebug() << r2.width();


20
20

I tried to check documentation but I didn't find any mention of these differences.

What is the reason for this? And how to use QRectF in the case of QGraphicsItem when drawing 1-pixel width line without antialiasing? Should I always adjust boundingRect().adjust(0,0,-1,-1) ?

Ludek Vodicka
  • 1,610
  • 1
  • 18
  • 33

1 Answers1

0

A bit late to the party. But today I stumbled accross the same issue. A look into the Qt docs revealed that all methods for access of bottom and right bear some "historical burden" (e.g. QRect::bottom()):

Note that for historical reasons this function returns top() + height() - 1; use y() + height() to retrieve the true y-coordinate.

See also Qt-Docs

Ulli Seifert
  • 26
  • 1
  • 4