内容表

上一话题

QContextMenuEvent

下一话题

QDesktopServices

QCursor

QCursor class provides a mouse cursor with an arbitrary shape. 更多

Inheritance diagram of PySide2.QtGui.QCursor

概要

函数

静态函数

详细描述

此类主要用于创建关联特定 Widget 的鼠标光标,及获取和设置鼠标光标的位置。

Qt 有许多标准光标形状,但也可以制作自定义光标形状基于 QBitmap 、遮罩及热点。

Widget 要关联光标,使用 setCursor() . To associate a cursor with all widgets (normally for a short period of time), use setOverrideCursor() .

要设置光标形状使用 setShape() or use the QCursor constructor which takes the shape as argument, or you can use one of the predefined cursors defined in the CursorShape 枚举。

If you want to create a cursor with your own bitmap, either use the QCursor constructor which takes a bitmap and a mask or the constructor which takes a pixmap as arguments.

要设置 (或获取) 鼠标光标的位置,使用静态方法 pos() and setPos() .

注意

It is possible to create a QCursor before QGuiApplication , but it is not useful except as a place-holder for a real QCursor created after QGuiApplication . Attempting to use a QCursor that was created before QGuiApplication 将导致崩溃。

X11 用户注意事项

在 X11,Qt 支持 Xcursor 库,允许全彩图标主题。下表展示的光标名称被用于每 CursorShape 值。若使用以下展示的名称找不到光标,则使用标准 X11 光标代替。注意:X11 没有提供适当光标为所有可能的 CursorShape 值。某些游标可能获取自 Xcursor 主题,而其它的使用内部位图光标。

形状

CursorShape

光标名称

形状

CursorShape

光标名称

cursor-arrow1

ArrowCursor

left_ptr

cursor-sizev2

SizeVerCursor

size_ver

cursor-uparrow3

UpArrowCursor

up_arrow

cursor-sizeh4

SizeHorCursor

size_hor

cursor-cross5

CrossCursor

cross

cursor-sizeb6

SizeBDiagCursor

size_bdiag

cursor-ibeam7

IBeamCursor

ibeam

cursor-sizef8

SizeFDiagCursor

size_fdiag

cursor-wait9

WaitCursor

wait

cursor-sizeall10

SizeAllCursor

size_all

cursor-busy11

BusyCursor

left_ptr_watch

cursor-vsplit12

SplitVCursor

split_v

cursor-forbidden13

ForbiddenCursor

forbidden

cursor-hsplit14

SplitHCursor

split_h

cursor-hand15

PointingHandCursor

pointing_hand

cursor-openhand16

OpenHandCursor

openhand

cursor-whatsthis17

WhatsThisCursor

whats_this

cursor-closedhand18

ClosedHandCursor

closedhand

DragMoveCursor

dnd-move or move

DragCopyCursor

dnd-copy or copy

DragLinkCursor

dnd-link or link

class QCursor

QCursor(shape)

QCursor(bitmap, mask[, hotX=-1[, hotY=-1]])

QCursor(cursor)

QCursor(pixmap[, hotX=-1[, hotY=-1]])

param mask

QBitmap

param shape

CursorShape

param hotX

int

param cursor

QCursor

param hotY

int

param bitmap

QBitmap

param pixmap

QPixmap

采用默认箭头形状构造光标。

构造光标采用指定 shape .

CursorShape 为形状列表。

另请参阅

setShape()

构造自定义位图光标。

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 ( )
返回类型

QBitmap

注意

此函数被弃用。

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 ( )
返回类型

QBitmap

注意

此函数被弃用。

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. __ne__ ( rhs )
参数

rhs QCursor

返回类型

bool

PySide2.QtGui.QCursor. __eq__ ( rhs )
参数

rhs QCursor

返回类型

bool

PySide2.QtGui.QCursor. pixmap ( )
返回类型

QPixmap

返回光标像素图。这才有效,若光标是像素图光标。

static PySide2.QtGui.QCursor. pos ( )
返回类型

QPoint

返回首要屏幕光标 (热点) 在全局屏幕坐标中的位置。

可以调用 mapFromGlobal() to translate it to widget coordinates.

注意

位置是从窗口系统查询。若通过其它手段 (如:在单元测试中通过 QWindowSystemInterface) 生成鼠标事件,那些虚假鼠标移动将不会反映在返回值中。

注意

在没有开窗系统或光标不可用的平台,返回位置基于透过 QWindowSystemInterface 生成的鼠标移动事件。

另请参阅

setPos() mapFromGlobal() mapToGlobal() primaryScreen()

static PySide2.QtGui.QCursor. pos ( screen )
参数

screen QScreen

返回类型

QPoint

返回光标 (热点) 的位置为 screen 在全局屏幕坐标中。

可以调用 mapFromGlobal() to translate it to widget coordinates.

另请参阅

setPos() mapFromGlobal() mapToGlobal()

static PySide2.QtGui.QCursor. setPos ( screen , p )
参数
  • screen QScreen

  • p QPoint

static 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()

static PySide2.QtGui.QCursor. setPos ( p )
参数

p QPoint

这是重载函数。

把光标 (热点) 移动全局屏幕位置,在点 p .

static 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 了解光标形状列表。

另请参阅

shape()

PySide2.QtGui.QCursor. shape ( )
返回类型

CursorShape

返回光标形状标识符。返回值是某一 CursorShape 枚举值 (铸造成 int)。

另请参阅

setShape()

PySide2.QtGui.QCursor. swap ( other )
参数

other QCursor

交换此光标与 other 光标。