QSplitterHandle 类

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 is typically what people think about when they think about a splitter. It is the handle that is used to resize the widgets.

A typical developer using QSplitter will never have to worry about QSplitterHandle. It is provided for developers who want splitter handles that provide extra features, such as popup menus.

The typical way one would create splitter handles is to subclass QSplitter and then reimplement QSplitter::createHandle () to instantiate the custom splitter handle. For example, a minimum QSplitter subclass might look like this:

class Splitter : public QSplitter
{
public:
    Splitter(Qt::Orientation orientation, QWidget *parent = nullptr);
protected:
    QSplitterHandle *createHandle() override;
};
					

The createHandle () implementation simply constructs a custom splitter handle, called Splitter in this example:

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

Information about a given handle can be obtained using functions like orientation () 和 opaqueResize (), and is retrieved from its parent splitter. Details like these can be used to give custom handles different appearances depending on the splitter's orientation.

The complexity of a custom handle subclass depends on the tasks that it needs to perform. A simple subclass might only provide a paintEvent () implementation:

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));
}
					

In this example, a predefined gradient is set up differently depending on the orientation of the handle. QSplitterHandle provides a reasonable size hint for the handle, so the subclass does not need to provide a reimplementation of sizeHint () unless the handle has special size requirements.

另请参阅 QSplitter .

成员函数文档编制

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

创建 QSplitter handle with the given orientation and parent .

[virtual noexcept] QSplitterHandle:: ~QSplitterHandle ()

析构函数。

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

Returns the closest legal position to pos of the splitter handle. The positions are measured from the left or top edge of the splitter, even for right-to-left languages.

另请参阅 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 )

Tells the splitter to move this handle to position pos , which is the distance from the left or top edge of the widget.

注意, pos is also measured from the left (or top) for right-to-left languages. This function will map pos to the appropriate position before calling QSplitter::moveSplitter ().

另请参阅 QSplitter::moveSplitter () 和 closestLegalPosition ().

bool QSplitterHandle:: opaqueResize () const

返回 true 若动态 (不透明) 重置 Widget 尺寸当交互移动分割器时。否则返回 false . This value is controlled by the QSplitter .

另请参阅 QSplitter::opaqueResize ().

Qt::Orientation QSplitterHandle:: orientation () const

Returns the handle's orientation. This is usually propagated from the 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 )

Sets the orientation of the splitter handle to orientation . This is usually propagated from the QSplitter .

另请参阅 orientation () 和 QSplitter::setOrientation ().

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

重实现访问函数为特性: QWidget::sizeHint .

QSplitter *QSplitterHandle:: splitter () const

返回关联此分割器手柄的分割器。

另请参阅 QSplitter::handle ().