#include <qsize.h>
A size is specified by a width() and a height(). It can be set in the constructor and changed using the setWidth(), setHeight(), or scale() functions, or using arithmetic operators. A size can also be manipulated directly by retrieving references to the width and height using the rwidth() and rheight() functions. Finally, the width and height can be swapped using the transpose() function.
The isValid() function determines if a size is valid. A valid size has both width and height greater than or equal to zero. The isEmpty() function returns true if either of the width and height is less than (or equal to) zero, while the isNull() function returns true only if both the width and the height is zero.
Use the expandedTo() function to retrieve a size which holds the maximum height and width of this size and a given size. Similarly, the boundedTo() function returns a size which holds the minimum height and width of this size and a given size.
The QSizeF class also provides the toSize() function returning a QSize copy of this size, constructed by rounding the width and height to the nearest integers.
QSizeF objects can be streamed as well as compared.
Definition at line 180 of file qsize.h.
Public Member Functions | |
| QSizeF () | |
| QSizeF (const QSize &sz) | |
| QSizeF (qreal w, qreal h) | |
| bool | isNull () const |
| bool | isEmpty () const |
| bool | isValid () const |
| qreal | width () const |
| qreal | height () const |
| void | setWidth (qreal w) |
| void | setHeight (qreal h) |
| void | transpose () |
| void | scale (qreal w, qreal h, Qt::AspectRatioMode mode) |
| void | scale (const QSizeF &s, Qt::AspectRatioMode mode) |
| QSizeF | expandedTo (const QSizeF &) const |
| QSizeF | boundedTo (const QSizeF &) const |
| qreal & | rwidth () |
| qreal & | rheight () |
| QSizeF & | operator+= (const QSizeF &) |
| QSizeF & | operator-= (const QSizeF &) |
| QSizeF & | operator *= (qreal c) |
| QSizeF & | operator/= (qreal c) |
| QSize | toSize () const |
Private Attributes | |
| qreal | wd |
| qreal | ht |
Friends | |
| bool | operator== (const QSizeF &, const QSizeF &) |
| bool | operator!= (const QSizeF &, const QSizeF &) |
| const QSizeF | operator+ (const QSizeF &, const QSizeF &) |
| const QSizeF | operator- (const QSizeF &, const QSizeF &) |
| const QSizeF | operator * (const QSizeF &, qreal) |
| const QSizeF | operator * (qreal, const QSizeF &) |
| const QSizeF | operator/ (const QSizeF &, qreal) |
Related Functions | |
| (Note that these are not member functions.) | |
| QDataStream & | operator<< (QDataStream &stream, const QSizeF &size) |
| QDataStream & | operator>> (QDataStream &stream, QSizeF &size) |
| QSizeF::QSizeF | ( | ) | [inline] |
Constructs an invalid size.
Definition at line 240 of file qsize.h.
Referenced by boundedTo(), expandedTo(), and scale().
| QSizeF::QSizeF | ( | const QSize & | size | ) | [inline] |
| QSizeF::QSizeF | ( | qreal | width, | |
| qreal | height | |||
| ) | [inline] |
| bool QSizeF::isNull | ( | ) | const [inline] |
| bool QSizeF::isEmpty | ( | ) | const [inline] |
| bool QSizeF::isValid | ( | ) | const [inline] |
| qreal QSizeF::width | ( | ) | const [inline] |
Returns the width.
Definition at line 260 of file qsize.h.
References wd.
Referenced by QTextDocument::adjustSize(), QAbstractFormBuilder::createProperty(), DocumentShape::DocumentShape(), QItemDelegate::drawDisplay(), QTextDocumentLayoutPrivate::drawFrame(), QTextDocumentLayoutPrivate::hitTest(), ImageShape::ImageShape(), QTextDocumentLayoutPrivate::layoutBlock(), QTextDocumentLayoutPrivate::layoutFlow(), QTextDocumentLayoutPrivate::layoutFrame(), operator<<(), ArthurFrame::paintDescription(), PreviewView::paintPage(), HoverPoints::pointBoundingRect(), QTextDocumentLayoutPrivate::positionFloat(), QTextDocument::print(), qDrawRoundedCorners(), QRectF::QRectF(), PreviewView::resizeEvent(), QTextDocumentLayout::resizeInlineObject(), PrintPreview::setup(), qdesigner_internal::SizeFProperty::setValue(), Launcher::showCategories(), Launcher::showExampleSummary(), TitleShape::TitleShape(), and Launcher::updateExampleSummary().
00261 { return wd; }
| qreal QSizeF::height | ( | ) | const [inline] |
Returns the height.
Definition at line 263 of file qsize.h.
References ht.
Referenced by QGraphicsTextItemPrivate::_q_updateBoundingRect(), QTextDocument::adjustSize(), TransEditor::calculateFieldHeight(), EditorPage::calculateFieldHeight(), QGraphicsTextItemPrivate::controlOffset(), QAbstractFormBuilder::createProperty(), DocumentShape::DocumentShape(), QItemDelegate::drawDisplay(), QTextDocumentLayoutPrivate::drawFrame(), QTextDocumentLayout::dynamicPageCount(), QTextDocumentLayoutPrivate::hitTest(), ImageShape::ImageShape(), QTextDocumentLayoutPrivate::layoutFlow(), QLabelPrivate::layoutRect(), operator<<(), PreviewView::paintEvent(), PreviewView::paintPage(), HoverPoints::pointBoundingRect(), QTextDocumentLayoutPrivate::positionFloat(), QTextDocument::print(), qDrawRoundedCorners(), QRectF::QRectF(), PreviewView::resizeEvent(), QTextDocumentLayout::resizeInlineObject(), PrintPreview::setup(), qdesigner_internal::SizeFProperty::setValue(), QGraphicsTextItemPrivate::textControl(), and TitleShape::TitleShape().
00264 { return ht; }
| void QSizeF::setWidth | ( | qreal | width | ) | [inline] |
Sets the width to the given width.
Definition at line 266 of file qsize.h.
References wd.
Referenced by operator>>(), QTextDocument::setTextWidth(), and PrintPreview::setup().
| void QSizeF::setHeight | ( | qreal | height | ) | [inline] |
Sets the height to the given height.
Definition at line 269 of file qsize.h.
References ht.
Referenced by operator>>(), QTextDocument::setTextWidth(), and PrintPreview::setup().
| void QSizeF::transpose | ( | ) |
Swaps the width and height values.
Definition at line 582 of file qsize.cpp.
| void QSizeF::scale | ( | qreal | width, | |
| qreal | height, | |||
| Qt::AspectRatioMode | mode | |||
| ) | [inline] |
Scales the size to a rectangle with the given width and height, according to the specified mode.
If mode is Qt::IgnoreAspectRatio, the size is set to (width, height). If mode is Qt::KeepAspectRatio, the current size is scaled to a rectangle as large as possible inside (width, height), preserving the aspect ratio. If mode is Qt::KeepAspectRatioByExpanding, the current size is scaled to a rectangle as small as possible outside (width, height), preserving the aspect ratio.
Example:
QSizeF t1(10, 12); t1.scale(60, 60, Qt::IgnoreAspectRatio); // t1 is (60, 60) QSizeF t2(10, 12); t2.scale(60, 60, Qt::KeepAspectRatio); // t2 is (50, 60) QSizeF t3(10, 12); t3.scale(60, 60, Qt::KeepAspectRatioByExpanding); // t3 is (60, 72)
Definition at line 272 of file qsize.h.
References QSizeF().
Here is the call graph for this function:

| void QSizeF::scale | ( | const QSizeF & | size, | |
| Qt::AspectRatioMode | mode | |||
| ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Scales the size to a rectangle with the given size, according to the specified mode.
Definition at line 628 of file qsize.cpp.
References ht, Qt::IgnoreAspectRatio, Qt::KeepAspectRatio, s, and wd.
00629 { 00630 if (mode == Qt::IgnoreAspectRatio) { 00631 wd = s.wd; 00632 ht = s.ht; 00633 } else { 00634 bool useHeight; 00635 qreal rw = s.ht * wd / ht; 00636 00637 if (mode == Qt::KeepAspectRatio) { 00638 useHeight = (rw <= s.wd); 00639 } else { // mode == Qt::KeepAspectRatioByExpanding 00640 useHeight = (rw >= s.wd); 00641 } 00642 00643 if (useHeight) { 00644 wd = rw; 00645 ht = s.ht; 00646 } else { 00647 ht = s.wd * ht / wd; 00648 wd = s.wd; 00649 } 00650 } 00651 }
| qreal & QSizeF::rwidth | ( | ) | [inline] |
Returns a reference to the width.
Using a reference makes it possible to manipulate the width directly. For example:
Definition at line 275 of file qsize.h.
References wd.
Referenced by QTextDocument::print().
00276 { return wd; }
| qreal & QSizeF::rheight | ( | ) | [inline] |
Returns a reference to the height.
Using a reference makes it possible to manipulate the height directly. For example:
Definition at line 278 of file qsize.h.
References ht.
Referenced by QTextDocument::print().
00279 { return ht; }
| QSizeF & QSizeF::operator *= | ( | qreal | factor | ) | [inline] |
| QSizeF & QSizeF::operator/= | ( | qreal | divisor | ) | [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Divides both the width and height by the given divisor and returns a reference to the size.
Definition at line 308 of file qsize.h.
00309 { 00310 Q_ASSERT(!qFuzzyCompare(c, 0)); 00311 wd = wd/c; ht = ht/c; 00312 return *this; 00313 }
| QSize QSizeF::toSize | ( | ) | const [inline] |
Returns an integer based copy of this size.
Note that the coordinates in the returned size will be rounded to the nearest integer.
Definition at line 331 of file qsize.h.
References ht, qRound(), and wd.
Referenced by QWhatsThat::QWhatsThat(), QTextEditPrivate::relayoutDocument(), QTextDocumentLayout::resizeInlineObject(), and QLabelPrivate::sizeForWidth().
Here is the call graph for this function:

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Multiplies the given size by the given factor and returns the result.
Definition at line 302 of file qsize.h.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Divides the given size by the given divisor and returns the result.
Definition at line 315 of file qsize.h.
| QDataStream & operator<< | ( | QDataStream & | stream, | |
| const QSizeF & | size | |||
| ) | [related] |
Writes the the given size to the given stream and returns a reference to the stream.
Definition at line 838 of file qsize.cpp.
| QDataStream & operator>> | ( | QDataStream & | stream, | |
| QSizeF & | size | |||
| ) | [related] |
Reads a size from the given stream into the given size and returns a reference to the stream.
Definition at line 854 of file qsize.cpp.
00855 { 00856 double w, h; 00857 s >> w; 00858 s >> h; 00859 sz.setWidth(qreal(w)); 00860 sz.setHeight(qreal(h)); 00861 return s; 00862 }
qreal QSizeF::wd [private] |
Definition at line 222 of file qsize.h.
Referenced by boundedTo(), expandedTo(), isEmpty(), isNull(), isValid(), operator *=(), operator+=(), operator-=(), operator/=(), QSizeF(), rwidth(), scale(), setWidth(), toSize(), transpose(), and width().
qreal QSizeF::ht [private] |
Definition at line 223 of file qsize.h.
Referenced by boundedTo(), expandedTo(), height(), isEmpty(), isNull(), isValid(), operator *=(), operator+=(), operator-=(), operator/=(), QSizeF(), rheight(), scale(), setHeight(), toSize(), and transpose().
1.5.1