Cursor Guard Classes¶
DACursorScoped and DAWaitCursorScoped are RAII-style cursor management classes that ensure automatic cursor restoration at scope exit, even if an exception is thrown.
Preview¶

A wait cursor only appears while a long-running operation executes, so a static screenshot shows the trigger button instead. Clicking it enters a two-second wait-cursor scope and restores the cursor afterwards.
Key Features¶
- ✅ RAII guard: Automatically restores the cursor when the scope ends
- ✅ Exception safe: Correctly restores even if an exception is thrown mid-operation
- ✅ Convenience macro:
DA_WAIT_CURSOR_SCOPED()enables the wait cursor in one line - ✅ Custom cursor:
DACursorScopedsupports anyQCursor
Class Relationships¶
classDiagram
class DACursorScoped {
+DACursorScoped(QCursor)
+setCursor(QCursor)
+release()
}
class DAWaitCursorScoped {
+DAWaitCursorScoped()
}
DACursorScoped <|-- DAWaitCursorScoped
Usage¶
1. Wait Cursor (Most Common)¶
Use the macro to display a wait cursor during a long-running operation:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
2. Custom Cursor¶
1 2 3 4 5 6 7 8 9 10 11 | |
3. Manual Release¶
1 2 3 4 5 6 7 | |
RAII Guarantee
The destructor of DACursorScoped restores the previous cursor. If you call release() before the destructor runs, the destructor becomes a no-op, giving you manual control over when restoration happens.
Core Properties & Methods¶
DACursorScoped¶
| Method | Description |
|---|---|
DACursorScoped(QCursor) |
Sets the cursor on construction |
setCursor(QCursor) |
Change the cursor |
release() |
Manually release — restore cursor early |
DAWaitCursorScoped¶
| Method / Macro | Description |
|---|---|
DAWaitCursorScoped() |
Constructs with Qt::WaitCursor |
DA_WAIT_CURSOR_SCOPED() |
Convenience macro — creates an anonymous instance |
References¶
- Header files:
src/DACursorScoped.h,src/DAWaitCursorScoped.h