このページでは

QSplitterHandle Class

QSplitterHandle クラスは、スプリッターのハンドル機能を提供します。詳細...

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

パブリック関数

QSplitterHandle(Qt::Orientation orientation, QSplitter *parent)
virtual ~QSplitterHandle()
bool opaqueResize() const
Qt::Orientation orientation() const
void setOrientation(Qt::Orientation orientation)
QSplitter *splitter() const

再実装されたパブリック関数

virtual QSize sizeHint() const override

プロテクト関数

int closestLegalPosition(int pos)
void moveSplitter(int pos)

再実装されたプロテクト関数

virtual bool event(QEvent *event) override
virtual void mouseMoveEvent(QMouseEvent *e) override
virtual void mousePressEvent(QMouseEvent *e) override
virtual void mouseReleaseEvent(QMouseEvent *e) override
virtual void paintEvent(QPaintEvent *) override
virtual void resizeEvent(QResizeEvent *event) override

詳細な説明

QSplitterHandle は、一般的に「スプリッター」と聞いて連想されるものです。これは、ウィジェットのサイズ変更に使用されるハンドルです。

QSplitter を使用する一般的な開発者は、QSplitterHandle について気にする必要は一切ありません。これは、ポップアップメニューなどの追加機能を備えたスプリッターハンドルを必要とする開発者のために提供されています。

スプリッターハンドルを作成する一般的な方法は、QSplitter をサブクラス化し、QSplitter::createHandle()を再実装してカスタムスプリッターハンドルをインスタンス化することです。たとえば、最低限のQSplitter サブクラスは次のようなものになります:

class Splitter : public QSplitter
{
public:
    Splitter(Qt::Orientation orientation, QWidget *parent = nullptr);

protected:
    QSplitterHandle *createHandle() override;
};

createHandle() の実装では、この例ではSplitter と呼ばれるカスタムスプリッターハンドルを単に生成するだけです:

QSplitterHandle *Splitter::createHandle()
{
    return new SplitterHandle(orientation(), this);
}

特定のハンドルに関する情報は、orientation() やopaqueResize() といった関数を使用して取得でき、その情報は親スプリッターから取得されます。このような詳細情報を利用することで、スプリッターの向きに応じてカスタムハンドルの外観を変えることができます。

カスタムハンドルのサブクラスの複雑さは、そのサブクラスが実行する必要のあるタスクによって異なります。単純なサブクラスであれば、paintEvent() の実装のみを提供すれば十分です:

void SplitterHandle::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    if (orientation() == Qt::Horizontal) {
        gradient.setStart(rect().left(), rect().height()/2);
        gradient.setFinalStop(rect().right(), rect().height()/2);
    } else {
        gradient.setStart(rect().width()/2, rect().top());
        gradient.setFinalStop(rect().width()/2, rect().bottom());
    }
    painter.fillRect(event->rect(), QBrush(gradient));
}

この例では、ハンドルの向きに応じて、あらかじめ定義されたグラデーションが異なる設定になります。QSplitterHandleはハンドルに適したサイズヒントを提供するため、ハンドルに特別なサイズ要件がない限り、サブクラスはsizeHint()を再実装する必要はありません。

QSplitterも参照してください 。

メンバ関数のドキュメント

[explicit] QSplitterHandle::QSplitterHandle(Qt::Orientation orientation, QSplitter *parent)

指定されたorientation およびparent を用いて、QSplitter ハンドルを作成します。

[virtual noexcept] QSplitterHandle::~QSplitterHandle()

デストラクタ。

[protected] int QSplitterHandle::closestLegalPosition(int pos)

スプリッターハンドルの位置のうち、pos に最も近い有効な位置を返します。位置は、右から左へ書く言語の場合でも、スプリッターの左端または上端から測定されます。

QSplitter::closestLegalPosition() およびmoveSplitter()も参照してください 。

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

QWidget::event(QEvent *event) を再実装します。

[override virtual protected] void QSplitterHandle::mouseMoveEvent(QMouseEvent *e)

QWidget::mouseMoveEvent(QMouseEvent *event) を再実装します。

[override virtual protected] void QSplitterHandle::mousePressEvent(QMouseEvent *e)

QWidget::mousePressEvent(QMouseEvent *event) を再実装します。

[override virtual protected] void QSplitterHandle::mouseReleaseEvent(QMouseEvent *e)

QWidget::mouseReleaseEvent(QMouseEvent *event) を再実装します。

[protected] void QSplitterHandle::moveSplitter(int pos)

スプリッターに対し、このハンドルをpos の位置に移動するよう指示します。 は、ウィジェットの左端または上端からの距離を表します。

なお、右から左へ書く言語の場合も、pos は左端(または上端)からの距離として測定される点に注意してください。この関数は、QSplitter::moveSplitter()を呼び出す前に、pos を適切な位置にマッピングします。

QSplitter::moveSplitter() およびclosestLegalPosition()も参照してください 。

bool QSplitterHandle::opaqueResize() const

スプリッターをインタラクティブに移動している間にウィジェットのサイズが動的に(不透明に)変更された場合、true を返します。それ以外の場合は、false を返します。この値は、QSplitter によって制御されます。

QSplitter::opaqueResize()も参照してください 。

Qt::Orientation QSplitterHandle::orientation() const

ハンドルの向きを返します。これは通常、QSplitter から受け継がれます。

setOrientation() およびQSplitter::orientation()も参照してください 。

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

QWidget::paintEvent(QPaintEvent *event) を再実装します。

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

QWidget::resizeEvent(QResizeEvent *event) を再実装します。

void QSplitterHandle::setOrientation(Qt::Orientation orientation)

スプリッターハンドルの向きをorientation に設定します。これは通常、QSplitter から引き継がれます。

orientation() およびQSplitter::setOrientation()も参照してください 。

[override virtual] QSize QSplitterHandle::sizeHint() const

プロパティ「QWidget::sizeHint 」のアクセス関数を再実装します。

QSplitter *QSplitterHandle::splitter() const

このスプリッターハンドルに関連付けられたスプリッターを返します。

QSplitter::handle()も参照してください 。

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