此类主要用于创建关联特定 Widget 的鼠标光标,及获取和设置鼠标光标的位置。
Qt 有许多标准光标形状,但也可以制作自定义光标形状基于
QBitmap、遮罩及热点。Widget 要关联光标,使用
setCursor(). To associate a cursor with all widgets (normally for a short period of time), usesetOverrideCursor().要设置光标形状使用
setShape()or use theQCursorconstructor which takes the shape as argument, or you can use one of the predefined cursors defined in theCursorShape枚举。If you want to create a cursor with your own bitmap, either use the
QCursorconstructor which takes a bitmap and a mask or the constructor which takes a pixmap as arguments.要设置 (或获取) 鼠标光标的位置,使用静态方法
pos()andsetPos().注意
It is possible to create a
QCursorbeforeQGuiApplication, but it is not useful except as a place-holder for a realQCursorcreated afterQGuiApplication. Attempting to use aQCursorthat was created beforeQGuiApplication将导致崩溃。
在 X11,Qt 支持 Xcursor 库,允许全彩图标主题。下表展示的光标名称被用于每
CursorShape值。若使用以下展示的名称找不到光标,则使用标准 X11 光标代替。注意:X11 没有提供适当光标为所有可能的CursorShape值。某些游标可能获取自 Xcursor 主题,而其它的使用内部位图光标。
形状
CursorShape值光标名称
形状
CursorShape值光标名称
![]()
ArrowCursor
left_ptr
![]()
SizeVerCursor
size_ver
![]()
UpArrowCursor
up_arrow
![]()
SizeHorCursor
size_hor
![]()
CrossCursor
cross
![]()
SizeBDiagCursor
size_bdiag
![]()
IBeamCursor
ibeam
![]()
SizeFDiagCursor
size_fdiag
![]()
WaitCursor
wait
![]()
SizeAllCursor
size_all
![]()
BusyCursor
left_ptr_watch
![]()
SplitVCursor
split_v
![]()
ForbiddenCursor
forbidden
![]()
SplitHCursor
split_h
![]()
PointingHandCursor
pointing_hand
![]()
OpenHandCursor
openhand
![]()
WhatsThisCursor
whats_this
![]()
ClosedHandCursor
closedhand
DragMoveCursor
dnd-moveormove
DragCopyCursor
dnd-copyorcopy
DragLinkCursor
dnd-linkorlink
QCursor
¶
采用默认箭头形状构造光标。
构造光标采用指定
shape
.
见
CursorShape
为形状列表。
另请参阅
构造自定义位图光标。
bitmap
and
mask
构成位图。
hotX
and
hotY
define the cursor’s hot spot.
若
hotX
为负数,它被设为
bitmap().width()/2
。若
hotY
为负数,它被设为
bitmap().height()/2
.
光标
bitmap
(B) 和
mask
(M) 位的组合像这样:
B=1 和 M=1 给出黑色。
B=0 和 M=1 给出白色。
B=0 和 M=0 给出透明。
B=1 and M=0 gives an XOR’d result under Windows, undefined results on all other platforms.
使用全局 Qt 颜色
color0
去绘制 0 像素和
color1
去绘制 1 像素在位图中。
有效光标大小从属显示硬件 (或底层窗口系统)。推荐使用 32 x 32 的光标,因为所有平台支持此大小。某些平台还支持 16 x 16、48 x 48 及 64 x 64 光标。
另请参阅
QBitmap()
setMask()
构造自定义像素图光标。
pixmap
是图像。它通常给出遮罩 (设置使用
setMask()
).
hotX
and
hotY
define the cursor’s hot spot.
若
hotX
为负数,它被设为
pixmap().width()/2
。若
hotY
为负数,它被设为
pixmap().height()/2
.
有效光标大小从属显示硬件 (或底层窗口系统)。推荐使用 32 x 32 的光标,因为所有平台支持此大小。某些平台还支持 16 x 16、48 x 48 及 64 x 64 光标。
另请参阅
QPixmap()
setMask()
PySide2.QtGui.QCursor.
bitmap
(
)
¶
注意
此函数被弃用。
New code should use the other overload which returns
QBitmap
by-value.
Returns the cursor bitmap, or
None
if it is one of the standard cursors.
PySide2.QtGui.QCursor.
hotSpot
(
)
¶
QPoint
返回光标热点,或 (0, 0) 若它是标准光标之一。
PySide2.QtGui.QCursor.
mask
(
)
¶
注意
此函数被弃用。
New code should use the other overload which returns
QBitmap
by-value.
Returns the cursor bitmap mask, or
None
if it is one of the standard cursors.
PySide2.QtGui.QCursor.
pos
(
)
¶
QPoint
返回首要屏幕光标 (热点) 在全局屏幕坐标中的位置。
可以调用
mapFromGlobal()
to translate it to widget coordinates.
注意
位置是从窗口系统查询。若通过其它手段 (如:在单元测试中通过 QWindowSystemInterface) 生成鼠标事件,那些虚假鼠标移动将不会反映在返回值中。
注意
在没有开窗系统或光标不可用的平台,返回位置基于透过 QWindowSystemInterface 生成的鼠标移动事件。
另请参阅
setPos()
mapFromGlobal()
mapToGlobal()
primaryScreen()
PySide2.QtGui.QCursor.
pos
(
screen
)
¶
screen
–
QScreen
QPoint
返回光标 (热点) 的位置为
screen
在全局屏幕坐标中。
可以调用
mapFromGlobal()
to translate it to widget coordinates.
另请参阅
setPos()
mapFromGlobal()
mapToGlobal()
PySide2.QtGui.QCursor.
setPos
(
screen
,
p
)
¶
screen
–
QScreen
p
–
QPoint
PySide2.QtGui.QCursor.
setPos
(
screen
,
x
,
y
)
¶
screen
–
QScreen
x
–
int
y
–
int
移动光标 (热点) 为
screen
到全局屏幕位置 (
x
,
y
).
可以调用
mapToGlobal()
to translate widget coordinates to global screen coordinates.
注意
Calling this function results in changing the cursor position through the windowing system. The windowing system will typically respond by sending mouse events to the application’s window. This means that the usage of this function should be avoided in unit tests and everywhere where fake mouse events are being injected via QWindowSystemInterface because the windowing system’s mouse state (with regards to buttons for example) may not match the state in the application-generated events.
注意
在没有窗口系统或光标不可用的平台,此函数可能什么都不做。
另请参阅
pos()
mapFromGlobal()
mapToGlobal()
PySide2.QtGui.QCursor.
setPos
(
p
)
¶
p
–
QPoint
这是重载函数。
把光标 (热点) 移动全局屏幕位置,在点
p
.
PySide2.QtGui.QCursor.
setPos
(
x
,
y
)
¶
x
–
int
y
–
int
把首要屏幕的光标 (热点) 移动到全局屏幕位置 (
x
,
y
).
可以调用
mapToGlobal()
to translate widget coordinates to global screen coordinates.
另请参阅
pos()
mapFromGlobal()
mapToGlobal()
primaryScreen()
PySide2.QtGui.QCursor.
setShape
(
newShape
)
¶
newShape
–
CursorShape
将光标设为标识形状通过
shape
.
见
CursorShape
了解光标形状列表。
另请参阅
PySide2.QtGui.QCursor.
shape
(
)
¶
CursorShape
返回光标形状标识符。返回值是某一
CursorShape
枚举值 (铸造成 int)。
另请参阅