QSize Class
The QSize class defines the size of a two-dimensional object using integer point precision. More…
| Header | #include <QSize> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Functions
| QSize() | |
| QSize(int w, int h) | |
| bool | isNull() const |
| bool | isEmpty() const |
| bool | isValid() const |
| int | width() const |
| int | height() const |
| void | setWidth(int w) |
| void | setHeight(int h) |
| int & | rwidth() |
| int & | rheight() |
| void | transpose() |
| QSize | transposed() const |
| QSize | expandedTo(const QSize &o) const |
| QSize | boundedTo(const QSize &o) const |
| void | scale(int w, int h, Qt::AspectRatioMode mode) |
| void | scale(const QSize &s, Qt::AspectRatioMode mode) |
| QSize | scaled(int w, int h, Qt::AspectRatioMode mode) const |
| QSize | scaled(const QSize &s, Qt::AspectRatioMode mode) const |
| QSizeF | toSizeF() const |
| QSize & | operator+=(const QSize &s) |
| QSize & | operator-=(const QSize &s) |
| QSize & | operator*=(double f) |
| QSize & | operator/=(double d) |
| QSize | grownBy(QMargins m) const |
| QSize | shrunkBy(QMargins m) const |
Detailed Description
A size is specified by a width() and a height(), both stored as int. A default-constructed size is invalid, with a width and height of -1. Use QSizeF for floating-point dimensions.
See also QSizeF, QPoint and QRect.
Differences from Qt
None.
Member Function Documentation
QSize::QSize()
Constructs a size with an invalid width and height, both -1.
See also isValid().
QSize::QSize(int w, int h)
Constructs a size with the given w and h.
QSize QSize::boundedTo(const QSize &o) const
Returns a size holding the minimum width and height of this size and the o size.
See also expandedTo().
QSize QSize::expandedTo(const QSize &o) const
Returns a size holding the maximum width and height of this size and the o size.
See also boundedTo().
QSize QSize::grownBy(QMargins m) const
Returns the size grown by the margins m: wider by the left and right margins and taller by the top and bottom ones.
This function was introduced in 5.14.
See also shrunkBy().
int QSize::height() const
Returns the height.
See also width(), setHeight() and rheight().
bool QSize::isEmpty() const
Returns true if the width or the height is less than 1; otherwise returns false.
See also isNull() and isValid().
bool QSize::isNull() const
Returns true if both the width and height are 0; otherwise returns false.
See also isEmpty() and isValid().
bool QSize::isValid() const
Returns true if both the width and the height are equal to or greater than 0; otherwise returns false.
See also isNull() and isEmpty().
QSize & QSize::operator*=(double f)
Multiplies both the width and height by the given factor f, rounds each to the nearest integer, and returns a reference to this size.
QSize & QSize::operator+=(const QSize &s)
Adds the given s to this size and returns a reference to this size.
QSize & QSize::operator-=(const QSize &s)
Subtracts the given s from this size and returns a reference to this size.
QSize & QSize::operator/=(double d)
Divides both the width and height by the given divisor d, rounds each to the nearest integer, and returns a reference to this size.
int & QSize::rheight()
Returns a reference to the height, allowing it to be modified directly.
See also height() and setHeight().
int & QSize::rwidth()
Returns a reference to the width, allowing it to be modified directly.
See also width() and setWidth().
void QSize::scale(int w, int h, Qt::AspectRatioMode mode)
This is an overloaded function.
Scales this size to a rectangle with the given w and h, according to the given mode.
void QSize::scale(const QSize &s, Qt::AspectRatioMode mode)
Scales this size to a rectangle with the given size s, according to the given mode.
See also scaled().
QSize QSize::scaled(int w, int h, Qt::AspectRatioMode mode) const
This is an overloaded function.
Returns this size scaled to a rectangle with the given w and h, according to the given mode.
QSize QSize::scaled(const QSize &s, Qt::AspectRatioMode mode) const
Returns this size scaled to a rectangle with the given size s, according to the given mode.
If mode is Qt::IgnoreAspectRatio, or this size has a zero width or height, s is returned unchanged. With Qt::KeepAspectRatio the result fits inside s; with Qt::KeepAspectRatioByExpanding it covers s.
See also scale().
void QSize::setHeight(int h)
Sets the height to the given h.
See also height() and setWidth().
void QSize::setWidth(int w)
Sets the width to the given w.
See also width() and setHeight().
QSize QSize::shrunkBy(QMargins m) const
Returns the size shrunk by the margins m.
This function was introduced in 5.14.
See also grownBy().
QSizeF QSize::toSizeF() const
Returns this size as a QSizeF.
See also QSizeF::toSize().
void QSize::transpose()
Swaps the width and height values.
See also transposed().
QSize QSize::transposed() const
Returns a size with the width and height values swapped.
See also transpose().
int QSize::width() const
Returns the width.
See also height(), setWidth() and rwidth().