Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Change mouse cursor shape for a desktop application when hovering over a QML element

    General and Desktop
    1
    1
    982
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      cristeab last edited by

      Hi

      I have a desktop application with UI written in QML. I am using mouse area to detect when the mouse hovers over a given region. When the mouse enters the region I am using:
      QCursor *cursor = QGuiApplication::overrideCursor();
      if (NULL != cursor) {
      QGuiApplication::restoreOverrideCursor();//empty stack first
      }
      QGuiApplication::setOverrideCursor(Qt::PointingHandCursor);

      then when the mouse leaves the region:

      QCursor *cursor = QGuiApplication::overrideCursor();
      if (NULL != cursor) {
          QGuiApplication::restoreOverrideCursor();
      }
      

      My approach seems to work, but I get situations, at application startup for example, when the mouse cursor does not change shape. When I hide the main window, then show it again the mouse cursor changes shape. For the main window I am using QQuickView as the base class and I am loading my QML files. For widgets I have seen that there is setMouseTracking method, but this one is not available for QQuickView. Could someone tell me what is the reliable way to change mouse cursor shape when hovering over a QML element ?

      thanks
      Bogdan

      1 Reply Last reply Reply Quote 0
      • First post
        Last post