QTabletEvent Class

The QTabletEvent class contains parameters that describe a Tablet event. More...

Header: #include <QTabletEvent>
qmake: QT += gui
Inherits: QInputEvent

Public Types

enum PointerType { UnknownPointer, Pen, Cursor, Eraser }
enum TabletDevice { NoDevice, Puck, Stylus, Airbrush, FourDMouse, RotationStylus }

Public Functions

QTabletEvent(QEvent::Type type, const QPointF &pos, const QPointF &globalPos, int device, int pointerType, qreal pressure, int xTilt, int yTilt, qreal tangentialPressure, qreal rotation, int z, Qt::KeyboardModifiers keyState, qint64 uniqueID, Qt::MouseButton button, Qt::MouseButtons buttons)
Qt::MouseButton button() const
Qt::MouseButtons buttons() const
QTabletEvent::TabletDevice device() const
QPoint globalPos() const
const QPointF &globalPosF() const
int globalX() const
int globalY() const
const QPointF &hiResGlobalPos() const
qreal hiResGlobalX() const
qreal hiResGlobalY() const
QTabletEvent::PointerType pointerType() const
QPoint pos() const
const QPointF &posF() const
qreal pressure() const
qreal rotation() const
qreal tangentialPressure() const
qint64 uniqueId() const
int x() const
int xTilt() const
int y() const
int yTilt() const
int z() const
  • 4 public functions inherited from QInputEvent
  • 6 public functions inherited from QEvent

Static Public Members

const QMetaObject staticMetaObject
  • 1 static public member inherited from QEvent

Protected Variables

int mDev
void *mExtra
QPointF mGPos
int mPointerType
QPointF mPos
qreal mPress
qreal mRot
qreal mTangential
qint64 mUnique
int mXT
int mYT
int mZ

Additional Inherited Members

  • 1 property inherited from QEvent

Detailed Description

The QTabletEvent class contains parameters that describe a Tablet event.

Tablet events are generated from tablet peripherals such as Wacom tablets and various other brands, and electromagnetic stylus devices included with some types of tablet computers. (It is not the same as QTouchEvent which a touchscreen generates, even when a passive stylus is used on a touchscreen.)

Tablet events are similar to mouse events; for example, the x(), y(), pos(), globalX(), globalY(), and globalPos() accessors provide the cursor position, and you can see which buttons() are pressed (pressing the stylus tip against the tablet surface is equivalent to a left mouse button). But tablet events also pass through some extra information that the tablet device driver provides; for example, you might want to do subpixel rendering with higher resolution coordinates (hiResGlobalX() and hiResGlobalY()), adjust color brightness based on the pressure() of the tool against the tablet surface, use different brushes depending on the type of tool in use (device()), modulate the brush shape in some way according to the X-axis and Y-axis tilt of the tool with respect to the tablet surface (xTilt() and yTilt()), and use a virtual eraser instead of a brush if the user switches to the other end of a double-ended stylus (pointerType()).

Every event contains an accept flag that indicates whether the receiver wants the event. You should call QTabletEvent::accept() if you handle the tablet event; otherwise it will be sent to the parent widget. The exception are TabletEnterProximity and TabletLeaveProximity events: these are only sent to QApplication and do not check whether or not they are accepted.

The QWidget::setEnabled() function can be used to enable or disable mouse, tablet and keyboard events for a widget.

The event handler QWidget::tabletEvent() receives TabletPress, TabletRelease and TabletMove events. Qt will first send a tablet event, then if it is not accepted by any widget, it will send a mouse event. This allows users of applications that are not designed for tablets to use a tablet like a mouse. However high-resolution drawing applications should handle the tablet events, because they can occur at a higher frequency, which is a benefit for smooth and accurate drawing. If the tablet events are rejected, the synthetic mouse events may be compressed for efficiency.

New in Qt 5.4: QTabletEvent includes all information available from the device, including QTabletEvent::buttons(). Previously it was not possible to accept all tablet events and also know which stylus buttons were pressed.

Note that pressing the stylus button while the stylus hovers over the tablet will generate a button press on some types of tablets, while on other types it will be necessary to press the stylus against the tablet surface in order to register the simultaneous stylus button press.

Notes for X11 Users

If the tablet is configured in xorg.conf to use the Wacom driver, there will be separate XInput "devices" for the stylus, eraser, and (optionally) cursor and touchpad. Qt recognizes these by their names. Otherwise, if the tablet is configured to use the evdev driver, there will be only one device and applications may not be able to distinguish the stylus from the eraser.

Notes for Windows Users

Tablet support currently requires the WACOM windows driver providing the DLL wintab32.dll to be installed. It is contained in older packages, for example pentablet_5.3.5-3.exe.

Member Type Documentation

enum QTabletEvent::PointerType

This enum defines what type of point is generating the event.

ConstantValueDescription
QTabletEvent::UnknownPointer0An unknown device.
QTabletEvent::Pen1Tip end of a stylus-like device (the narrow end of the pen).
QTabletEvent::Cursor2Any puck-like device.
QTabletEvent::Eraser3Eraser end of a stylus-like device (the broad end of the pen).

See also pointerType().

enum QTabletEvent::TabletDevice

This enum defines what type of device is generating the event.

ConstantValueDescription
QTabletEvent::NoDevice0No device, or an unknown device.
QTabletEvent::Puck1A Puck (a device that is similar to a flat mouse with a transparent circle with cross-hairs).
QTabletEvent::Stylus2A Stylus.
QTabletEvent::Airbrush3An airbrush
QTabletEvent::FourDMouse4A 4D Mouse.
QTabletEvent::RotationStylus6A special stylus that also knows about rotation (a 6D stylus).

This enum was introduced or modified in Qt 4.1.

Member Function Documentation

QTabletEvent::QTabletEvent(QEvent::Type type, const QPointF &pos, const QPointF &globalPos, int device, int pointerType, qreal pressure, int xTilt, int yTilt, qreal tangentialPressure, qreal rotation, int z, Qt::KeyboardModifiers keyState, qint64 uniqueID, Qt::MouseButton button, Qt::MouseButtons buttons)

Construct a tablet event of the given type.

The pos parameter indicates where the event occurred in the widget; globalPos is the corresponding position in absolute coordinates.

pressure contains the pressure exerted on the device.

pointerType describes the type of pen that is being used.

xTilt and yTilt contain the device's degree of tilt from the x and y axes respectively.

keyState specifies which keyboard modifiers are pressed (e.g., Ctrl).

The uniqueID parameter contains the unique ID for the current device.

The z parameter contains the coordinate of the device on the tablet, this is usually given by a wheel on 4D mouse. If the device does not support a Z-axis, pass zero here.

The tangentialPressure parameter contins the tangential pressure of an air brush. If the device does not support tangential pressure, pass 0 here.

rotation contains the device's rotation in degrees. 4D mice, the Wacom Art Pen, and the Apple Pencil support rotation. If the device does not support rotation, pass 0 here.

The button that caused the event is given as a value from the Qt::MouseButton enum. If the event type is not TabletPress or TabletRelease, the appropriate button for this event is Qt::NoButton.

buttons is the state of all buttons at the time of the event.

See also pos(), globalPos(), device(), pressure(), xTilt(), yTilt(), uniqueId(), rotation(), tangentialPressure(), and z().

Qt::MouseButton QTabletEvent::button() const

Returns the button that caused the event.

Note that the returned value is always Qt::NoButton for TabletMove, TabletEnterProximity and TabletLeaveProximity events.

See also buttons() and Qt::MouseButton.

Qt::MouseButtons QTabletEvent::buttons() const

Returns the button state when the event was generated. The button state is a combination of buttons from the Qt::MouseButton enum using the OR operator. For TabletMove events, this is all buttons that are pressed down. For TabletPress events this includes the button that caused the event. For TabletRelease events this excludes the button that caused the event.

See also button() and Qt::MouseButton.

QTabletEvent::TabletDevice QTabletEvent::device() const

QPoint QTabletEvent::globalPos() const

const QPointF &QTabletEvent::globalPosF() const

int QTabletEvent::globalX() const

int QTabletEvent::globalY() const

const QPointF &QTabletEvent::hiResGlobalPos() const

qreal QTabletEvent::hiResGlobalX() const

qreal QTabletEvent::hiResGlobalY() const

QTabletEvent::PointerType QTabletEvent::pointerType() const

QPoint QTabletEvent::pos() const

const QPointF &QTabletEvent::posF() const

qreal QTabletEvent::pressure() const

qreal QTabletEvent::rotation() const

qreal QTabletEvent::tangentialPressure() const

qint64 QTabletEvent::uniqueId() const

int QTabletEvent::x() const

int QTabletEvent::xTilt() const

int QTabletEvent::y() const

int QTabletEvent::yTilt() const

int QTabletEvent::z() const