QScrollBar 類

The QScrollBar 小部件提供垂直 (或水平) 滾動條。 更多...

頭: #include <QScrollBar>
qmake: QT += widgets
繼承: QAbstractSlider

公共函數

QScrollBar (QWidget * parent = Q_NULLPTR)
QScrollBar (Qt::Orientation orientation , QWidget * parent = Q_NULLPTR)
~QScrollBar ()

重實現公共函數

virtual bool event (QEvent * event )
virtual QSize sizeHint () const

保護函數

void initStyleOption (QStyleOptionSlider * option ) const

重實現保護函數

virtual void contextMenuEvent (QContextMenuEvent * event )
virtual void hideEvent ( QHideEvent * )
virtual void mouseMoveEvent (QMouseEvent * e )
virtual void mousePressEvent (QMouseEvent * e )
virtual void mouseReleaseEvent (QMouseEvent * e )
virtual void paintEvent ( QPaintEvent * )
virtual void sliderChange (SliderChange change )
virtual void wheelEvent (QWheelEvent * event )

額外繼承成員

詳細描述

The QScrollBar 小部件提供垂直 (或水平) 滾動條。

滾動條是控件,使用戶能夠訪問 > 用於顯示文檔的 Widget 的文檔部分。它為用戶提供當前文檔位置及可見文檔數量的視覺指示。滾動條通常裝備有其它控件,使導航更精確。Qt 以適閤各平颱的方式顯示滾動條。

If you need to provide a scrolling view onto another widget, it may be more convenient to use the QScrollArea class because this provides a viewport widget and scroll bars. QScrollBar is useful if you need to implement similar functionality for specialized widgets using QAbstractScrollArea ; for example, if you decide to subclass QAbstractItemView . For most other situations where a slider control is used to obtain a value within a given range, the QSlider class may be more appropriate for your needs.

Scroll bars typically include four separate controls: a slider, scroll arrows, and a page control.
  • a. The slider provides a way to quickly go to any part of the document, but does not support accurate navigation within large documents.
  • b. The scroll arrows are push buttons which can be used to accurately navigate to a particular place in a document. For a vertical scroll bar connected to a text editor, these typically move the current position one "line" up or down, and adjust the position of the slider by a small amount. In editors and list boxes a "line" might mean one line of text; in an image viewer it might mean 20 pixels.
  • c. The page control is the area over which the slider is dragged (the scroll bar's background). Clicking here moves the scroll bar towards the click by one "page". This value is usually the same as the length of the slider.

Each scroll bar has a value that indicates how far the slider is from the start of the scroll bar; this is obtained with value () 和設置采用 setValue (). This value always lies within the range of values defined for the scroll bar, from minimum() to maximum() inclusive. The range of acceptable values can be set with setMinimum () 和 setMaximum (). At the minimum value, the top edge of the slider (for a vertical scroll bar) or left edge (for a horizontal scroll bar) will be at the top (or left) end of the scroll bar. At the maximum value, the bottom (or right) edge of the slider will be at the bottom (or right) end of the scroll bar.

The length of the slider is usually related to the value of the page step, and typically represents the proportion of the document area shown in a scrolling view. The page step is the amount that the value changes by when the user presses the Page Up and Page Down keys, and is set with setPageStep (). Smaller changes to the value defined by the line step are made using the cursor keys, and this quantity is set with setSingleStep() .

Note that the range of values used is independent of the actual size of the scroll bar widget. You do not need to take this into account when you choose values for the range and the page step.

The range of values specified for the scroll bar are often determined differently to those for a QSlider because the length of the slider needs to be taken into account. If we have a document with 100 lines, and we can only show 20 lines in a widget, we may wish to construct a scroll bar with a page step of 20, a minimum value of 0, and a maximum value of 80. This would give us a scroll bar with five "pages".

The relationship between a document length, the range of values used in a scroll bar, and the page step is simple in many common situations. The scroll bar's range of values is determined by subtracting a chosen page step from some value representing the length of the document. In such cases, the following equation is useful: document length = maximum () - minimum () + pageStep ().

QScrollBar 僅提供整數範圍。注意,盡管 QScrollBar handles very large numbers, scroll bars on current screens cannot usefully represent ranges above about 100,000 pixels. Beyond that, it becomes difficult for the user to control the slider using either the keyboard or the mouse, and the scroll arrows will have limited use.

ScrollBar inherits a comprehensive set of signals from QAbstractSlider :

A scroll bar can be controlled by the keyboard, but it has a default focusPolicy () of Qt::NoFocus 。使用 setFocusPolicy () to enable keyboard interaction with the scroll bar:

  • 左/右箭頭水平移動滾動條一單步幅。
  • 上/下箭頭垂直移動滾動條一單步幅。
  • PageUp 鍵上移一頁。
  • PageDown 鍵下移一頁。
  • Home 鍵移至開頭 (最小)。
  • End 鍵移至結束 (最大)。

The slider itself can be controlled by using the triggerAction() function to simulate user interaction with the scroll bar controls. This is useful if you have many different widgets that use a common range of values.

大多數 GUI 樣式使用 pageStep () value to calculate the size of the slider.

另請參閱 QScrollArea , QSlider , QDial , QSpinBox , GUI Design Handbook: Scroll Bar ,和 滑塊範例 .

成員函數文檔編製

QScrollBar:: QScrollBar ( QWidget * parent = Q_NULLPTR)

構造垂直滾動條。

The parent 自變量被發送給 QWidget 構造函數。

The minimum 默認為 0, maximum 到 99,采用 singleStep 1 尺寸和 pageStep 10 尺寸,及初始 value of 0.

QScrollBar:: QScrollBar ( Qt::Orientation orientation , QWidget * parent = Q_NULLPTR)

構造滾動條采用給定 orientation .

The parent 自變量會被傳遞給 QWidget 構造函數。

The minimum 默認為 0, maximum 到 99,采用 singleStep 1 尺寸和 pageStep 10 尺寸,及初始 value of 0.

QScrollBar:: ~QScrollBar ()

銷毀滾動條。

[virtual protected] void QScrollBar:: contextMenuEvent ( QContextMenuEvent * event )

重實現自 QWidget::contextMenuEvent ().

[虛擬] bool QScrollBar:: event ( QEvent * event )

重實現自 QObject::event ().

[virtual protected] void QScrollBar:: hideEvent ( QHideEvent * )

重實現自 QWidget::hideEvent ().

[protected] void QScrollBar:: initStyleOption ( QStyleOptionSlider * option ) const

初始化 option 采用值來自此 QScrollBar 。此方法對子類是有用的,當需要 QStyleOptionSlider ,但不希望自己填充所有信息。

另請參閱 QStyleOption::initFrom ().

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

重實現自 QWidget::mouseMoveEvent ().

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

重實現自 QWidget::mousePressEvent ().

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

重實現自 QWidget::mouseReleaseEvent ().

[virtual protected] void QScrollBar:: paintEvent ( QPaintEvent * )

重實現自 QWidget::paintEvent ().

[虛擬] QSize QScrollBar:: sizeHint () const

重實現自 QWidget::sizeHint ().

[virtual protected] void QScrollBar:: sliderChange ( SliderChange change )

重實現自 QAbstractSlider::sliderChange ().

[virtual protected] void QScrollBar:: wheelEvent ( QWheelEvent * event )

重實現自 QWidget::wheelEvent ().