QSize Class

QSizeクラスは、2次元オブジェクトのサイズを整数点精度で定義します。詳細...

ヘッダー #include <QSize>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

パブリック関数

QSize()
QSize(int width, int height)
QSize boundedTo(const QSize &otherSize) const
QSize expandedTo(const QSize &otherSize) const
QSize grownBy(QMargins margins) const
int height() const
bool isEmpty() const
bool isNull() const
bool isValid() const
int &rheight()
int &rwidth()
void scale(int width, int height, Qt::AspectRatioMode mode)
void scale(const QSize &size, Qt::AspectRatioMode mode)
QSize scaled(int width, int height, Qt::AspectRatioMode mode) const
QSize scaled(const QSize &s, Qt::AspectRatioMode mode) const
void setHeight(int height)
void setWidth(int width)
QSize shrunkBy(QMargins margins) const
CGSize toCGSize() const
(since 6.4) QSizeF toSizeF() const
void transpose()
QSize transposed() const
int width() const
QSize &operator*=(qreal factor)
QSize &operator+=(const QSize &size)
QSize &operator-=(const QSize &size)
QSize &operator/=(qreal divisor)
bool operator!=(const QSize &lhs, const QSize &rhs)
QSize operator*(const QSize &size, qreal factor)
QSize operator*(qreal factor, const QSize &size)
QSize operator+(const QSize &s1, const QSize &s2)
QSize operator-(const QSize &s1, const QSize &s2)
QSize operator/(const QSize &size, qreal divisor)
QDataStream &operator<<(QDataStream &stream, const QSize &size)
bool operator==(const QSize &lhs, const QSize &rhs)
QDataStream &operator>>(QDataStream &stream, QSize &size)

詳細説明

サイズはwidth() とheight() で指定する。コンストラクタで設定したり、setWidth()、setHeight()、scale() 関数や算術演算子を使って変更することができます。また、rwidth() やrheight() 関数を使って幅や高さの参照を取得し、サイズを直接操作することもできます。最後に、transpose ()関数を使用して、幅と高さを入れ替えることができる。

isValid() 関数は、サイズが有効かどうかを判定する(有効なサイズは、幅と高さの両方が 0 以上である)。isEmpty() 関数は、幅と高さのいずれかがゼロ以下の場合にtrue を返し、isNull() 関数は、幅と高さの両方がゼロの場合にのみtrue を返す。

expandedTo() 関数を使用して、このサイズと指定されたサイズの最大の高さと幅を保持するサイズを取得する。同様に、boundedTo ()関数は、このサイズと与えられたサイズの最小の高さと幅を保持するサイズを返します。

QSize オブジェクトは、比較だけでなくストリームすることもできます。

QSizeFQPointQRectも参照のこと

メンバ関数ドキュメント

[constexpr noexcept] QSize QSize::grownBy(QMargins margins) const

このサイズをmargins だけ大きくしたサイズを返す。

shrunkBy()も参照

[constexpr noexcept] QSize QSize::shrunkBy(QMargins margins) const

このサイズをmargins だけ縮小した結果を返します。

grownBy()も参照

[constexpr noexcept] QSize::QSize()

無効な幅と高さを持つサイズを構築します(つまり、isValid() はfalse を返します)。

isValid()も参照

[constexpr noexcept] QSize::QSize(int width, int height)

与えられたwidthheight でサイズを構築する。

setWidth() およびsetHeight()も参照

[constexpr noexcept] QSize QSize::boundedTo(const QSize &otherSize) const

このサイズと与えられたotherSize の幅と高さの最小値を保持するサイズを返します。

expandedTo() およびscale()も参照

[constexpr noexcept] QSize QSize::expandedTo(const QSize &otherSize) const

このサイズと与えられたotherSize の最大幅と最大高さを保持するサイズを返します。

boundedTo() およびscale()も参照

[constexpr noexcept] int QSize::height() const

高さを返します。

width() およびsetHeight()も参照

[constexpr noexcept] bool QSize::isEmpty() const

幅と高さのどちらかが 0 以下の場合はtrue を返し、そうでない場合はfalse を返す。

isNull() およびisValid()も参照

[constexpr noexcept] bool QSize::isNull() const

幅と高さの両方が 0 の場合はtrue を返し、そうでない場合は false を返す。

isValid() およびisEmpty()も参照

[constexpr noexcept] bool QSize::isValid() const

幅と高さの両方が 0 以上の場合はtrue を返し、そうでない場合はfalse を返す。

isNull() およびisEmpty()も参照

[constexpr noexcept] int &QSize::rheight()

高さへの参照を返します。

参照を使用すると、高さを直接操作できるようになります。例えば

QSize size(100, 10);
size.rheight() += 5;

// size becomes (100,15)

rwidth() およびsetHeight()も参照

[constexpr noexcept] int &QSize::rwidth()

幅への参照を返す。

参照を使用すると、幅を直接操作できるようになります。例えば

QSize size(100, 10);
size.rwidth() += 20;

// size becomes (120,10)

rheight() およびsetWidth()も参照

[noexcept] void QSize::scale(int width, int height, Qt::AspectRatioMode mode)

与えられたwidthheight を持つ矩形に、指定されたmode に従ってサイズをスケーリングします:

  • modeQt::IgnoreAspectRatio の場合、サイズは (width,height) に設定される。
  • modeQt::KeepAspectRatio の場合,現在のサイズは,縦横比を保ったまま, (width,height) 内のできるだけ大きな矩形に拡大縮小される。
  • modeQt::KeepAspectRatioByExpanding の場合、 現在のサ イ ズは、 縦横比を保っ た ま ま、 (width,height) の外側にで き る だけ小 さ い矩形に縮小 さ れます。

例:

QSize t1(10, 12);
t1.scale(60, 60, Qt::IgnoreAspectRatio);
// t1 is (60, 60)

QSize t2(10, 12);
t2.scale(60, 60, Qt::KeepAspectRatio);
// t2 is (50, 60)

QSize t3(10, 12);
t3.scale(60, 60, Qt::KeepAspectRatioByExpanding);
// t3 is (60, 72)

setWidth()、setHeight()、scaled()も参照

[noexcept] void QSize::scale(const QSize &size, Qt::AspectRatioMode mode)

これはオーバーロードされた関数である。

サイズを,指定されたmode に従って,与えられたsize を持つ矩形にスケーリングします。

[noexcept] QSize QSize::scaled(int width, int height, Qt::AspectRatioMode mode) const

与えられたwidthheight を持つ矩形に、指定されたmode に従ってスケーリングされたサイズを返します。

scale()も参照

[noexcept] QSize QSize::scaled(const QSize &s, Qt::AspectRatioMode mode) const

これはオーバーロードされた関数である。

与えられたサイズs を持つ矩形に,指定されたmode に従ってスケーリングされたサイズを返す。

[constexpr noexcept] void QSize::setHeight(int height)

与えられたheight に高さを設定する。

rheight(),height(),setWidth()も参照

[constexpr noexcept] void QSize::setWidth(int width)

幅を指定されたwidth に設定する。

rwidth(),width(),setHeight()も参照

[noexcept] CGSize QSize::toCGSize() const

QSize から CGSize を作成する。

QSizeF::fromCGSize()も参照

[constexpr noexcept, since 6.4] QSizeF QSize::toSizeF() const

このサイズを浮動小数点精度のサイズとして返します。

この関数は Qt 6.4 で導入されました。

QSizeF::toSize()も参照してください

[noexcept] void QSize::transpose()

幅と高さの値を入れ替えます。

setWidth()、setHeight() およびtransposed()も参照

[constexpr noexcept] QSize QSize::transposed() const

幅と高さを入れ替えたQSize を返す。

transpose()も参照 ください。

[constexpr noexcept] int QSize::width() const

幅を返す。

height() およびsetWidth()も参照

[constexpr noexcept] QSize &QSize::operator*=(qreal factor)

これはオーバーロードされた関数である。

幅と高さの両方を与えられたfactor で乗算し、サイズへの参照を返します。

結果は最も近い整数に丸められることに注意してください。

scale()も参照

[constexpr noexcept] QSize &QSize::operator+=(const QSize &size)

与えられたsizeこのサイズに追加し、このサイズへの参照を返します。例えば

QSize s( 3, 7);
QSize r(-1, 4);
s += r;

// s becomes (2,11)

[constexpr noexcept] QSize &QSize::operator-=(const QSize &size)

このサイズから与えられたsize を引き、このサイズへの参照を返す。例えば

QSize s( 3, 7);
QSize r(-1, 4);
s -= r;

// s becomes (4,3)

QSize &QSize::operator/=(qreal divisor)

これはオーバーロードされた関数である。

幅と高さの両方を与えられたdivisor で割り、サイズへの参照を返します。

結果は最も近い整数に丸められることに注意してください。

QSize::scale()も参照してください

関連する非会員

[constexpr noexcept] bool operator!=(const QSize &lhs, const QSize &rhs)

lhsrhs が異なる場合はtrue を返し、そうでない場合はfalse を返す。

[constexpr noexcept] QSize operator*(const QSize &size, qreal factor)

指定されたsize を指定されたfactor で乗算し、最も近い整数に丸めた結果を返します。

QSize::scale()も参照

[constexpr noexcept] QSize operator*(qreal factor, const QSize &size)

これはオーバーロードされた関数である。

与えられたsize を与えられたfactor で乗算し、最も近い整数に丸めた結果を返します。

[constexpr noexcept] QSize operator+(const QSize &s1, const QSize &s2)

s1s2 の合計を返す。各コンポーネントは別々に加算される。

[constexpr noexcept] QSize operator-(const QSize &s1, const QSize &s2)

s1 からs2 を差し引いた値を返す。

QSize operator/(const QSize &size, qreal divisor)

これはオーバーロードされた関数である。

与えられたsize を与えられたdivisor で割り、最も近い整数に丸めた結果を返します。

QSize::scale()も参照

QDataStream &operator<<(QDataStream &stream, const QSize &size)

与えられたsize を与えられたstream に書き込み、ストリームへの参照を返します。

Qt データ型のシリアライズも参照してください

[constexpr noexcept] bool operator==(const QSize &lhs, const QSize &rhs)

lhsrhs が等しければtrue を返し、そうでなければfalse を返す。

QDataStream &operator>>(QDataStream &stream, QSize &size)

与えられたstream から与えられたsize にサイズを読み込み、ストリームへの参照を返します。

Qt データ型のシリアライズも参照してください

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.