QRubberBand Class

QRubberBandクラスは、選択範囲や境界を示す矩形や線を提供します。詳細...

ヘッダー #include <QRubberBand>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
継承: QWidget

パブリックな型

enum Shape { Line, Rectangle }

パブリック関数

QRubberBand(QRubberBand::Shape s, QWidget *p = nullptr)
virtual ~QRubberBand()
void move(int x, int y)
void move(const QPoint &p)
void resize(int width, int height)
void resize(const QSize &size)
void setGeometry(const QRect &rect)
void setGeometry(int x, int y, int width, int height)
QRubberBand::Shape shape() const

保護された関数

virtual void initStyleOption(QStyleOptionRubberBand *option) const

再実装された保護された関数

virtual void changeEvent(QEvent *e) override
virtual bool event(QEvent *e) override
virtual void moveEvent(QMoveEvent *) override
virtual void paintEvent(QPaintEvent *) override
virtual void resizeEvent(QResizeEvent *) override
virtual void showEvent(QShowEvent *e) override

詳しい説明

ラバーバンドは、(ドッキングを解除するQSplitterQDockWidget のように)新しい境界領域を表示するためによく使用されます。歴史的に、これはQPainter と XOR を使って実装されてきましたが、ラバーバンドの下のウィンドウで、ラバーバンドが「消去」される前にレンダリングが行われることがあるため、この方法は必ずしも正しく動作しません。

指定した領域(または1本の線)の周りに輪ゴムをレンダリングする必要がある場合はいつでもQRubberBandを作成し、setGeometry ()、move ()、resize ()を呼び出して位置とサイズを指定します。よくあるパターンは、マウス・イベントと連動させることです。例えば

void Widget::mousePressEvent(QMouseEvent *event)
{
    origin = event->pos();
    if (!rubberBand)
        rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
    rubberBand->setGeometry(QRect(origin, QSize()));
    rubberBand->show();
}

void Widget::mouseMoveEvent(QMouseEvent *event)
{
    rubberBand->setGeometry(QRect(origin, event->pos()).normalized());
}

void Widget::mouseReleaseEvent(QMouseEvent *event)
{
    rubberBand->hide();
    // determine selection, for example using QRect::intersects()
    // and QRect::contains().
}

QRubberBandのコンストラクタに親を渡すと、ラバーバンドは親の内部でのみ表示され、他の子ウィジェットの上に留まります。親を渡さなかった場合、QRubberBand はトップレベルのウィジェットとして動作します。

ラバーバンドを表示するには、show() を呼び出します。ラバーバンドがトップレベルでない場合も同様です。ウィジェットを隠すか破棄すると、ラバーバンドは消えます。ラバーバンドは、構築時に与えられたshape() によって、Rectangle またはLine (垂直または水平) になります。

メンバ型ドキュメント

enum QRubberBand::Shape

この列挙型は、QRubberBand がどのような形状を持つべきかを指定する。これは、スタイルシステムに渡される描画ヒントであり、各QStyle によって解釈されます。

定数説明
QRubberBand::Line0QRubberBand は、縦線または横線を表すことができます。ジオメトリはまだrect() で与えられ、線はほとんどのスタイルで与えられたジオメトリを埋めます。
QRubberBand::Rectangle1QRubberBand は矩形を表すことができます。スタイルによっては、これを塗りつぶされた(しばしば半透明の)矩形、または矩形の輪郭として解釈します。

メンバ関数ドキュメント

[explicit] QRubberBand::QRubberBand(QRubberBand::Shape s, QWidget *p = nullptr)

親をp とするs 形状の輪ゴムを構築します。

デフ ォ ル ト では、 長方形の輪ゴム (sRectangle ) はマス ク を用い る ので、 矩形の小 さ な枠がすべて見え る よ う にな り ます。い く つかのス タ イル (た と えばネ イ テ ィ ブな macOS) は こ れを変更 し 、QWidget::setWindowOpacity () を呼び出 し て、 半透明の塗りつぶし選択矩形を作成 し ます。

[virtual noexcept] QRubberBand::~QRubberBand()

破壊者。

[override virtual protected] void QRubberBand::changeEvent(QEvent *e)

再実装:QWidget::changeEvent(QEvent *event)。

[override virtual protected] bool QRubberBand::event(QEvent *e)

再実装:QWidget::event(QEvent *event)。

[virtual protected] void QRubberBand::initStyleOption(QStyleOptionRubberBand *option) const

QRubberBand の値でoption を初期化する。このメソッドは、サブクラスがQStyleOptionRubberBand を必要とするが、すべての情報を自分で入力したくない場合に便利です。

QStyleOption::initFrom()も参照

void QRubberBand::move(int x, int y)

ラバーバンドを点 (x,y) に移動する。

resize()も参照

void QRubberBand::move(const QPoint &p)

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

ラバーバンドを点p に移動する。

resize()も参照

[override virtual protected] void QRubberBand::moveEvent(QMoveEvent *)

再実装:QWidget::moveEvent(QMoveEvent *event)。

[override virtual protected] void QRubberBand::paintEvent(QPaintEvent *)

再実装:QWidget::paintEvent(QPaintEvent *event)。

void QRubberBand::resize(int width, int height)

幅がwidth 、高さがheight になるように、ラバーバンドのサイズを変更します。

move()も参照

void QRubberBand::resize(const QSize &size)

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

新しいサイズがsize になるようにラバーバンドのサイズを変更する。

move()も参照

[override virtual protected] void QRubberBand::resizeEvent(QResizeEvent *)

再実装:QWidget::resizeEvent(QResizeEvent *event)。

void QRubberBand::setGeometry(const QRect &rect)

ラバーバンドのジオメトリを、親ウィジェットの座標系で指定されたrect に設定します。

QWidget::geometryも参照してください

void QRubberBand::setGeometry(int x, int y, int width, int height)

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

ラバーバンドのジオメトリを、左上隅が点 (x,y) に位置し、寸法がwidthheight で指定される矩形に設定します。ジオメトリは親ウィジェットの座標系で指定されます。

QRubberBand::Shape QRubberBand::shape() const

このゴムバンドの形状を返します。形状は作成時にのみ設定できます。

[override virtual protected] void QRubberBand::showEvent(QShowEvent *e)

再実装:QWidget::showEvent(QShowEvent *event)。

© 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.