[frameworks] Hide cursor when tablet pen leaves proximity of the screen

Review Request #128858 - Created Sept. 7, 2016 and updated

Oliver Sander

I am trying to fix the following papercut: I regularly write on pdf files in presentation mode, using the pen that comes with my Lenovo ThinkPad Yoga. When I approach the screen with the pen, the cursor appears, and it follows the pen tip during writing. When I lift off the pen, the cursor stays on, and auto-hides only a few seconds later (because of Okular::Settings::EnumSlidesCursor::HiddenDelay). As a consequence, the cursor frequently hides the last bits of what I have just written. This is a nuisance, because I do this in front of an audience, and a lot of it is math (where every detail matters).

Ideally, the cursor would auto-hide when I lift the pen off the screen. Luckily, Qt has an event for this: QEvent::TabletLeaveProximity. Unluckily, the documentation says (http://doc.qt.io/qt-5/qtabletevent.html):

"TabletEnterProximity and TabletLeaveProximity events [...] are only sent to QApplication"

Therefore, this patch introduces a new class TabletApplication, which inherits from QApplication, and is used in main.cpp instead of QApplication. The proximity events are really caught, and each time a short note is printed on the console.

Unfortunately, at this point I am stuck and need some help. Apparently, I cannot control the cursor from a QApplication. How do I get the information that a TabletProximity has been caught to the presentation widget? Maybe the answer is trivial, but I have very little Qt programming experience. Thanks for your help!



  • 0
  • 2
  • 1
  • 3
Description From Last Updated
Martin Tobias Holmedahl Sandsmark
Oliver Sander
Oliver Sander
Albert Astals Cid
Oliver Sander
Review request changed

Change Summary:

TabletLeaveProximity: if the cursor mode is 'always visible', switch back to arrow cursor instead of blank cursor.


Revision 4 (+40 -2)

Show changes

Albert Astals Cid

ui/presentationwidget.cpp (Diff revision 4)

Why this change?

  1. Previously, the code there was

      slotChangeDrawingToolEngine( QDomElement() );
      slotChangeDrawingToolEngine( m_currentDrawingToolElement );

    And here is the content of slotChangeDrawingToolEngine:

    if ( element.isNull() )
        delete m_drawingEngine;
        m_drawingEngine = 0;
        m_drawingRect = QRect();
        setCursor( Qt::ArrowCursor );
        m_drawingEngine = new SmoothPathEngine( element );
        setCursor( QCursor( QPixmap( QStringLiteral("pencil") ), Qt::ArrowCursor ) );
        m_currentDrawingToolElement = element;

    You can see that it sets the cursor shape, but we don't want that: When drawing with the stylus we want the cursor to remain a CrossCursor, not change back to ArrowCursor. But the cursor change is really only a by-product of the calls to this method. Therefore I simply inlined the calls to slotChangeDrawingToolEngine, and omitted the cursor change.

Albert Astals Cid

Ok, if you find that this works for you, at least i can't find any regression on the "old" code, so it should be good to ship.

  1. Don't you mind that it is still unclear why the extra code at presentationwidget.cpp:730 is needed at all? I could not look at this because some Qt quirk broke the whole patch for me a few month ago (no more proximity events at all). Updating to Qt 5.9 brought the patch back to life just last week, and I was planning to have another look.

  2. your decision.