27 int m_cursorIndex = 0;
32QCursor createCenterHotspotCursor()
34 QPixmap cursor(64, 64);
35 cursor.fill(Qt::transparent);
38 const QPoint center = cursor.rect().center();
39 p.drawLine(0, center.y(), center.x() - 1, center.y());
40 p.drawLine(center.x() + 1, center.y(), cursor.width(), center.y());
41 p.drawLine(center.x(), 0, center.x(), center.y() - 1);
42 p.drawLine(center.x(), center.y() + 1, center.x(), cursor.height());
43 return QCursor(cursor, 31, 31);
46QCursor createTopLeftHotspotCursor()
48 QPixmap cursor(64, 64);
49 cursor.fill(Qt::transparent);
52 p.drawLine(0, 1, 0, cursor.height());
53 p.drawLine(1, 0, cursor.width(), 0);
54 return QCursor(cursor, 0, 0);
57QCursor createTopRightHotspotCursor()
59 QPixmap cursor(64, 64);
60 cursor.fill(Qt::transparent);
63 p.drawLine(cursor.width() - 1, 1, cursor.width() - 1, cursor.height());
64 p.drawLine(0, 0, cursor.width() - 2, 0);
65 return QCursor(cursor, 63, 0);
68QCursor createButtomRightHotspotCursor()
70 QPixmap cursor(64, 64);
71 cursor.fill(Qt::transparent);
74 p.drawLine(cursor.width() - 1, 0, cursor.width() - 1, cursor.height() - 2);
75 p.drawLine(0, cursor.height() - 1, cursor.width() - 2, cursor.height() - 1);
76 return QCursor(cursor, 63, 63);
79QCursor createButtomLeftHotspotCursor()
81 QPixmap cursor(64, 64);
82 cursor.fill(Qt::transparent);
85 p.drawLine(0, 0, 0, cursor.height() - 2);
86 p.drawLine(1, cursor.height() - 1, cursor.width(), cursor.height() - 1);
87 return QCursor(cursor, 0, 63);
95 setMouseTracking(
true);
97 m_cursors[0] = createCenterHotspotCursor();
98 m_cursors[1] = createTopLeftHotspotCursor();
99 m_cursors[2] = createTopRightHotspotCursor();
100 m_cursors[3] = createButtomRightHotspotCursor();
101 m_cursors[4] = createButtomLeftHotspotCursor();
103 setCursor(m_cursors[m_cursorIndex]);
111 p.fillRect(0, 0, width(), height(), Qt::white);
112 if (geometry().contains(m_cursorPos)) {
114 p.drawPoint(m_cursorPos);
120 m_cursorPos =
event->pos();
126 if (event->key() == Qt::Key_Space) {
127 m_cursorIndex = (m_cursorIndex + 1) % 5;
128 setCursor(m_cursors[m_cursorIndex]);
132int main(
int argc,
char *argv[])
134 QApplication app(argc, argv);
142#include "cursorhotspottest.moc"