QScroller 類

The QScroller class enables kinetic scrolling for any scrolling widget or graphics item. 更多...

頭: #include <QScroller>
qmake: QT += widgets
Since: Qt 5.0
繼承: QObject

公共類型

enum Input { InputPress, InputMove, InputRelease }
enum ScrollerGestureType { TouchGesture, LeftMouseButtonGesture, MiddleMouseButtonGesture, RightMouseButtonGesture }
enum State { Inactive, Pressed, Dragging, Scrolling }

特性

公共函數

QPointF finalPosition () const
bool handleInput (QScroller::Input input , const QPointF & position , qint64 timestamp = 0)
QPointF pixelPerMeter () const
QScrollerProperties scrollerProperties () const
void setSnapPositionsX (const QList<qreal> & positions )
void setSnapPositionsX (qreal first , qreal interval )
void setSnapPositionsY (const QList<qreal> & positions )
void setSnapPositionsY (qreal first , qreal interval )
QScroller::State state () const
void stop ()
QObject * target () const
QPointF velocity () const

公共槽

void ensureVisible (const QRectF & rect , qreal xmargin , qreal ymargin )
void ensureVisible (const QRectF & rect , qreal xmargin , qreal ymargin , int scrollTime )
void resendPrepareEvent ()
void scrollTo (const QPointF & pos )
void scrollTo (const QPointF & pos , int scrollTime )
void setScrollerProperties (const QScrollerProperties & prop )

信號

void scrollerPropertiesChanged (const QScrollerProperties & newProperties )
void stateChanged (QScroller::State newState )

靜態公共成員

QList<QScroller *> activeScrollers ()
Qt::GestureType grabGesture (QObject * target , QScroller::ScrollerGestureType scrollGestureType = TouchGesture)
Qt::GestureType grabbedGesture (QObject * target )
bool hasScroller (QObject * target )
QScroller * scroller (QObject * target )
const QScroller * scroller (const QObject * target )
const QMetaObject staticMetaObject
void ungrabGesture (QObject * target )

額外繼承成員

詳細描述

The QScroller class enables kinetic scrolling for any scrolling widget or graphics item.

采用動感滾動,用戶可以沿給定方嚮推動 Widget,且將繼續沿此方嚮捲動直到被用戶 (或摩擦) 停止。可以改變慣性、摩擦和其它物理概念的各個方麵,為微調直觀用戶體驗。

The QScroller object is the object that stores the current position and scrolling speed and takes care of updates. QScroller can be triggered by a flick gesture

    QWidget *w = ...;
    QScroller::grabGesture(w, QScroller::LeftMouseButtonGesture);
					

或直接像這樣:

    QWidget *w = ...;
    QScroller *scroller = QScroller::scroller(w);
    scroller->scrollTo(QPointF(100, 100));
					

捲動的 QObject 接收 QScrollPrepareEvent 每當捲動器需要更新其幾何體信息時和 QScrollEvent 每當對象內容實際上應滾動時。

捲動器使用全局 QAbstractAnimation 計時器來生成其 QScrollEvent。這可以改變采用 QScrollerProperties::FrameRate on a per- QScroller basis.

Several examples in the scroller examples directory show how QScroller , QScrollEvent and the scroller gesture can be used.

盡管此動感捲動器擁有大量可用設置憑藉 QScrollerProperties ,推薦將它們全部保持在其默認、平颱優化值。在更改它們之前,可以實驗性采用 plot 範例在 scroller 範例目錄。

另請參閱 QScrollEvent , QScrollPrepareEvent ,和 QScrollerProperties .

成員類型文檔編製

enum QScroller:: Input

此枚舉包含輸入設備不可知視圖對於輸入事件相關 QScroller .

常量 描述
QScroller::InputPress 1 用戶按下輸入設備 (如 QEvent::MouseButtonPress , QEvent::GraphicsSceneMousePress , QEvent::TouchBegin )
QScroller::InputMove 2 用戶移動輸入設備 (如 QEvent::MouseMove , QEvent::GraphicsSceneMouseMove , QEvent::TouchUpdate )
QScroller::InputRelease 3 用戶釋放輸入設備 (如 QEvent::MouseButtonRelease , QEvent::GraphicsSceneMouseRelease , QEvent::TouchEnd )

enum QScroller:: ScrollerGestureType

此枚舉包含的不同手勢類型支持通過 QScroller 手勢識彆器。

常量 描述
QScroller::TouchGesture 0 手勢識彆器僅在觸摸事件時纔觸發。具體來說,它對單觸摸點作齣反應當使用觸摸屏時,和對雙觸摸點作齣反應當使用觸摸闆時。
QScroller::LeftMouseButtonGesture 1 手勢識彆器僅在鼠標左鍵事件時纔觸發。
QScroller::MiddleMouseButtonGesture 3 手勢識彆器僅在鼠標中鍵事件時纔觸發。
QScroller::RightMouseButtonGesture 2 手勢識彆器僅在鼠標右鍵事件時纔觸發。

enum QScroller:: State

此枚舉包含不同 QScroller 狀態。

常量 描述
QScroller::Inactive 0 捲動器不捲動且什麼都未按下。
QScroller::Pressed 1 收到觸摸事件或按下鼠標按鈕,但目前未拖拽捲動區域。
QScroller::Dragging 2 捲動區域目前跟隨觸摸點 (或鼠標)。
QScroller::Scrolling 3 捲動區域正在自行移動。

特性文檔編製

scrollerProperties : QScrollerProperties

此特性保持此捲動器的捲動特性。特性用於 QScroller 以確定其捲動行為。

訪問函數:

QScrollerProperties scrollerProperties () const
void setScrollerProperties (const QScrollerProperties & prop )

通知程序信號:

void scrollerPropertiesChanged (const QScrollerProperties & newProperties )

state : const State

此特性保持滾軸的狀態

訪問函數:

QScroller::State state () const

通知程序信號:

void stateChanged (QScroller::State newState )

另請參閱 QScroller::State .

成員函數文檔編製

[static] QList < QScroller *> QScroller:: activeScrollers ()

返迴應用程序範圍列錶的當前活動 QScroller 對象。活動 QScroller 對象處於 state () 非 QScroller::Inactive 。此函數很有用,當編寫自己的手勢識彆器時。

[slot] void QScroller:: ensureVisible (const QRectF & rect , qreal xmargin , qreal ymargin )

開始捲動以便矩形 rect 在視口內可見,采用額外邊距以像素為單位指定通過 xmargin and ymargin 圍繞矩形。

當不可能將矩形加邊距擬閤在視口內時,會滾動內容以便盡可能多地可見從 rect .

會計算捲動速度,以便到達給定位置在平颱定義的時間跨度後。

此函數履行實際捲動通過調用 scrollTo ().

另請參閱 scrollTo ().

[slot] void QScroller:: ensureVisible (const QRectF & rect , qreal xmargin , qreal ymargin , int scrollTime )

這是重載函數。

此版本將到達其目標位置在 scrollTime 毫秒。

QPointF QScroller:: finalPosition () const

返迴當前捲動運動的最終估計位置。返迴當前位置,若捲動器狀態不為 Scrolling。結果未定義,當捲動器狀態為 Inactive 時。

目標位置以像素為單位。

另請參閱 pixelPerMeter () 和 scrollTo ().

[static] Qt::GestureType QScroller:: grabGesture ( QObject * target , QScroller::ScrollerGestureType scrollGestureType = TouchGesture)

注冊自定義捲動手勢識彆器,抓取它為 target 並返迴結果手勢類型。若 scrollGestureType 被設為 TouchGesture 手勢在觸摸事件時纔觸發。若它被設為某一 LeftMouseButtonGesture , RightMouseButtonGesture or MiddleMouseButtonGesture 它在相應按鈕鼠標事件時纔觸發。

在一個對象中隻可以同時活動一個捲動手勢。若在同一對象中調用此函數 2 次,它將取消現有手勢抓取在抓取新手勢之前。

注意: 為避免不想要的副作用,會消耗鼠標事件當觸發手勢時。由於初始鼠標按下事件未被消耗,所以手勢會發送僞鼠標釋放事件在全局位置 (INT_MIN, INT_MIN) 。這確保收到原始鼠標按下的 Widget 的內部狀態一緻。

另請參閱 ungrabGesture () 和 grabbedGesture ().

[static] Qt::GestureType QScroller:: grabbedGesture ( QObject * target )

返迴目前抓取的手勢類型對於 target 或 0 若沒有抓取手勢。

另請參閱 grabGesture () 和 ungrabGesture ().

bool QScroller:: handleInput ( QScroller::Input input , const QPointF & position , qint64 timestamp = 0)

手勢識彆器使用此函數,通報捲動器有關新輸入事件。捲動器改變其內部 state () 根據輸入事件及其附加的捲動器特性。捲動器不區分事件來自哪種輸入設備。因此,需要將事件拆分成 input 類型, position 和毫秒 timestamp position 需要在目標坐標係中。

返迴值為 true 若事件應該被調用過濾器消耗或 false 若事件應該被轉發給控件。

注意: 使用 grabGesture () 對於大多數用例而言應該足夠瞭。

[static] bool QScroller:: hasScroller ( QObject * target )

返迴 true QScroller 對象已創建為 target ; false 否則。

另請參閱 scroller ().

QPointF QScroller:: pixelPerMeter () const

返迴捲動 Widget 的每米像素規格。

分彆報告 X 軸和 Y 軸兩者的值通過使用 QPointF .

注意: Please note that this value should be physically correct. The actual DPI settings that Qt returns for the display may be reported wrongly on purpose by the underlying windowing system, for example on macOS .

[slot] void QScroller:: resendPrepareEvent ()

此函數重新發送 QScrollPrepareEvent 。調用 resendPrepareEvent 觸發 QScrollPrepareEvent 從捲動器。這允許接收器重新設置內容位置和內容大小當捲動時。當在 Inactive 狀態下調用此函數是無用的,因為會再次發送準備事件在捲動開始之前。

[slot] void QScroller:: scrollTo (const QPointF & pos )

開始捲動 Widget 以便點 pos 位於視口左上位置。

行為未定義當在有效捲動區域之外捲動時。在這種情況下,捲動器可能 (或不可能) 過衝。

將計算捲動速度,以便在平颱定義的時間跨度後到達給定位置。

pos 按視口坐標給定。

另請參閱 ensureVisible ().

[slot] void QScroller:: scrollTo (const QPointF & pos , int scrollTime )

這是重載函數。

此版本將到達其目標位置在 scrollTime 毫秒。

[static] QScroller *QScroller:: scroller ( QObject * target )

返迴捲動器為給定 target 。隻要對象存在,此函數將始終返迴相同 QScroller 實例。若無 QScroller 存在對於 target ,將隱式創建一個。在任何時候僅一 QScroller 將活動在對象上。

另請參閱 hasScroller () 和 target ().

[static] const QScroller *QScroller:: scroller (const QObject * target )

這是重載函數。

This is the const version of scroller ().

[signal] void QScroller:: scrollerPropertiesChanged (const QScrollerProperties & newProperties )

QScroller 發射此信號每當其捲動器特性改變時。 newProperties 是新捲動器特性。

注意: 通知程序信號對於特性 scrollerProperties .

另請參閱 scrollerProperties .

void QScroller:: setSnapPositionsX (const QList < qreal > & positions )

將水平軸的捕捉位置設為列錶 positions 。這會覆寫所有先前設置的捕捉位置及先前設置的捕捉間隙。可以通過設置空位置列錶以取消激活捕捉。

void QScroller:: setSnapPositionsX ( qreal first , qreal interval )

將水平軸的捕捉位置設為常規間隔間隙。首個捕捉位置在 first 。下一在 first + interval 。這可以用於實現列錶 Header (頭)。這會覆寫所有先前設置的捕捉位置及先前設置的捕捉間隙。可以通過將間隙設為 0.0 以取消激活捕捉

void QScroller:: setSnapPositionsY (const QList < qreal > & positions )

將垂直軸的捕捉位置設為列錶 positions 。這會覆寫所有先前設置的捕捉位置及先前設置的捕捉間隙。可以通過設置空位置列錶以取消激活捕捉。

void QScroller:: setSnapPositionsY ( qreal first , qreal interval )

將垂直軸的捕捉位置設為常規間隔間隙。首個捕捉位置在 first 。下一在 first + interval 。這會覆寫所有先前設置的捕捉位置及先前設置的捕捉間隙。可以通過將間隙設為 0.0 以取消激活捕捉

[signal] void QScroller:: stateChanged ( QScroller::State newState )

QScroller 發射此信號,每當狀態變化時。 newState 是新狀態。

注意: 通知程序信號對於特性 state .

另請參閱 state .

void QScroller:: stop ()

停止捲動器並將其狀態重置迴 Inactive。

QObject *QScroller:: target () const

返迴此捲動器的目標對象。

另請參閱 hasScroller () 和 scroller ().

[static] void QScroller:: ungrabGesture ( QObject * target )

取消手勢抓取為 target 。什麼都不做,若沒有手勢被抓取。

另請參閱 grabGesture () 和 grabbedGesture ().

QPointF QScroller:: velocity () const

返迴當前捲動速度 (以米/秒為單位) 當狀態為 Scrolling (捲動) 或 Dragging (拖拽) 時。否則,返迴 0 速度。

分彆報告 X 軸和 Y 軸兩者的速度通過使用 QPointF .

另請參閱 pixelPerMeter ().