The QCursor 類提供具有任意形狀的鼠標光標。 更多...
| 頭: | #include <QCursor> |
| QCursor () | |
| QCursor (Qt::CursorShape shape ) | |
| QCursor (const QBitmap & bitmap , const QBitmap & mask , int hotX = -1, int hotY = -1) | |
| QCursor (const QPixmap & pixmap , int hotX = -1, int hotY = -1) | |
| QCursor (const QCursor & c ) | |
| QCursor (HCURSOR cursor ) | |
| QCursor (Qt::HANDLE handle ) | |
| ~QCursor () | |
| const QBitmap * | bitmap () const |
| HCURSOR_or_HANDLE | handle () const |
| QPoint | hotSpot () const |
| const QBitmap * | mask () const |
| QPixmap | pixmap () const |
| void | setShape (Qt::CursorShape shape ) |
| Qt::CursorShape | shape () const |
| operator QVariant () const | |
| QCursor & | operator= (const QCursor & c ) |
| QCursor & | operator= (QCursor && other ) |
| QPoint | pos () |
| void | setPos (int x , int y ) |
| void | setPos (const QPoint & p ) |
| QDataStream & | operator<< (QDataStream & stream , const QCursor & cursor ) |
| QDataStream & | operator>> (QDataStream & stream , QCursor & cursor ) |
The QCursor 類提供具有任意形狀的鼠標光標。
此類主要用於創建關聯特定 Widget 的鼠標光標,及獲取和設置鼠標光標的位置。
Qt 有許多標準光標形狀,但也可以製作自定義光標形狀基於 QBitmap 、遮罩及熱點。
Widget 要關聯光標,使用 QWidget::setCursor ()。要關聯光標與所有 Widget (通常為短時間周期),使用 QApplication::setOverrideCursor ().
要設置光標形狀使用 QCursor::setShape () 或使用 QCursor 構造函數接受形狀作為自變量,或者可以使用某一預定義光標的定義在 Qt::CursorShape 枚舉。
若想要采用自己的位圖創建光標,要麼使用 QCursor 構造函數接受位圖和遮罩作為自變量,或構造函數接受像素圖作為自變量。
要設置 (或獲取) 鼠標光標的位置,使用靜態方法 QCursor::pos () 和 QCursor::setPos ().
注意: 它是可能的創建 QCursor before QApplication ,但它沒什麼用,除瞭作為占位符對於真實 QCursor 的創建後於 QApplication 。試圖使用 QCursor 創建的先於 QApplication 將導緻崩潰。
在 X11,Qt 支持 Xcursor 庫,允許全彩圖標主題。下錶展示的光標名稱被用於每 Qt::CursorShape 值。若使用以下展示的名稱找不到光標,則使用標準 X11 光標代替。注意:X11 沒有提供適當光標為所有可能的 Qt::CursorShape 值。某些遊標可能獲取自 Xcursor 主題,而其它的使用內部位圖光標。
| 形狀 | Qt::CursorShape 值 | 光標名稱 | 形狀 | Qt::CursorShape 值 | 光標名稱 |
|---|---|---|---|---|---|
|
Qt::ArrowCursor |
left_ptr
|
|
Qt::SizeVerCursor |
size_ver
|
|
Qt::UpArrowCursor |
up_arrow
|
|
Qt::SizeHorCursor |
size_hor
|
|
Qt::CrossCursor |
cross
|
|
Qt::SizeBDiagCursor |
size_bdiag
|
|
Qt::IBeamCursor |
ibeam
|
|
Qt::SizeFDiagCursor |
size_fdiag
|
|
Qt::WaitCursor |
wait
|
|
Qt::SizeAllCursor |
size_all
|
|
Qt::BusyCursor |
left_ptr_watch
|
|
Qt::SplitVCursor |
split_v
|
|
Qt::ForbiddenCursor |
forbidden
|
|
Qt::SplitHCursor |
split_h
|
|
Qt::PointingHandCursor |
pointing_hand
|
|
Qt::OpenHandCursor |
openhand
|
|
Qt::WhatsThisCursor |
whats_this
|
|
Qt::ClosedHandCursor |
closedhand
|
| Qt::DragMoveCursor |
dnd-move
or
move
|
Qt::DragCopyCursor |
dnd-copy
or
copy
|
||
| Qt::DragLinkCursor |
dnd-link
or
link
|
另請參閱 QWidget and GUI 設計手冊:光標 .
采用默認箭頭形狀構造光標。
構造光標采用指定 shape .
見 Qt::CursorShape 為形狀列錶。
另請參閱 setShape ().
構造自定義位圖光標。
bitmap and mask 構成位圖。 hotX and hotY 定義光標的熱點。
若
hotX
為負,它被設為
bitmap().width()/2
。若
hotY
為負,它被設為
bitmap().height()/2
.
光標 bitmap (B) 和 mask (M) 位的組閤像這樣:
使用全局 Qt 顔色 Qt::color0 去繪製 0 像素和 Qt::color1 去繪製 1 像素在位圖中。
有效光標大小從屬顯示硬件 (或底層窗口係統)。推薦使用 32 x 32 的光標,因為所有平颱支持此大小。某些平颱還支持 16 x 16、48 x 48 及 64 x 64 光標。
注意: On Windows CE, the cursor size is fixed. If the pixmap is bigger than the system size, it will be scaled.
另請參閱 QBitmap::QBitmap () 和 QBitmap::setMask ().
構造自定義像素圖光標。
pixmap 是圖像。它通常給齣遮罩 (設置使用 QPixmap::setMask ()). hotX and hotY 定義光標的熱點。
若
hotX
為負,它被設為
pixmap().width()/2
。若
hotY
為負,它被設為
pixmap().height()/2
.
有效光標大小從屬顯示硬件 (或底層窗口係統)。推薦使用 32 x 32 的光標,因為所有平颱支持此大小。某些平颱還支持 16 x 16、48 x 48 及 64 x 64 光標。
注意: On Windows CE, the cursor size is fixed. If the pixmap is bigger than the system size, it will be scaled.
另請參閱 QPixmap::QPixmap () 和 QPixmap::setMask ().
構造拷貝為光標 c .
Constructs a Qt cursor from the given Windows cursor .
警告: This function is only available on Windows.
另請參閱 handle ().
Constructs a Qt cursor from the given handle .
警告: This function is only available on X11.
另請參閱 handle ().
銷毀光標。
返迴光標位圖,或 0 若它是標準光標之一。
Returns a platform-specific cursor handle. The
HCURSOR_or_HANDLE
type is
HCURSOR
在 Windows 和
Qt::HANDLE
on X11 and Mac OS X. On
Qt for Embedded Linux
it is an integer.
警告: Using the value returned by this function is not portable.
返迴光標熱點,或 (0, 0) 若它是標準光標之一。
返迴光標位圖遮罩,或 0 若它是標準光標之一。
返迴光標像素圖。這纔有效,若光標是像素圖光標。
[static]
QPoint
QCursor::
pos
()
Returns the position of the cursor (hot spot) in global screen coordinates.
可以調用 QWidget::mapFromGlobal () 以將其翻譯成 Widget 坐標。
另請參閱 setPos (), QWidget::mapFromGlobal (),和 QWidget::mapToGlobal ().
[static]
void
QCursor::
setPos
(
int
x
,
int
y
)
Moves the cursor (hot spot) to the global screen position ( x , y ).
可以調用 QWidget::mapToGlobal () 以將 Widget 坐標翻譯成全局屏幕坐標。
另請參閱 pos (), QWidget::mapFromGlobal (),和 QWidget::mapToGlobal ().
[static]
void
QCursor::
setPos
(const
QPoint
&
p
)
這是重載函數。
把光標 (熱點) 移動全局屏幕位置,在點 p .
將光標設為標識形狀通過 shape .
見 Qt::CursorShape 瞭解光標形狀列錶。
另請參閱 shape ().
返迴光標形狀標識符。返迴值是某一 Qt::CursorShape 枚舉值 (鑄造成 int)。
另請參閱 setShape ().
返迴光標作為 QVariant .
賦值 c 給此光標並返迴此光標的引用。
寫入 cursor 到 stream .
另請參閱 序列化 Qt 數據類型 .
讀取 cursor 從 stream .
另請參閱 序列化 Qt 數據類型 .