Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Hiding mouse cursor, qt quick
Qt 6.11 is out! See what's new in the release blog

Hiding mouse cursor, qt quick

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.4k Views
  • 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.
  • H Offline
    H Offline
    hazbody21
    wrote on last edited by hazbody21
    #1

    Re: Hiding mouse cursor in QML

    Tried both solutions given in this thread separately but they don't seem to do anything to the display, a pointer always shows up at the top left of the display. Other solutions attempted are creating a mouse area under the window and blanking that cursor, but I don't even have a mouse plugged in and will strictly use a touch screen.

    Here is my main.qml:

    import QtQuick
    import QtQuick.Window 2.15
    import QtQuick.Controls 2.0
    import io.qt.backend 1.0
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
        HoverHandler {
            id: mouse
            cursorShape: Qt.BlankCursor
        }
    }
    

    and main.cpp

    #include <QGuiApplication>
    
    #include <QQmlApplicationEngine>
    
    
    int main(int argc, char *argv[])
    {
        if (qEnvironmentVariableIsEmpty("QTGLESSTREAM_DISPLAY")) {
            qputenv("QT_QPA_EGLFS_PHYSICAL_WIDTH", QByteArray("213"));
            qputenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT", QByteArray("120"));
    
    #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
            QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    #endif
        }
        QGuiApplication app(argc, argv);
        QGuiApplication::setOverrideCursor;
    
        QQmlApplicationEngine engine;
        const QUrl url(QStringLiteral("qrc:/main.qml"));
        QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
            &app, [url](QObject *obj, const QUrl &objUrl) {
                if (!obj && url == objUrl)
                    QCoreApplication::exit(-1);
            }, Qt::QueuedConnection);
        engine.load(url);
    
        return app.exec();
    }
    

    for this second solution I get warning: statement has no effect [-Wunused-value]

    using qt 6.5, ubuntu,

    GrecKoG 1 Reply Last reply
    0
    • H hazbody21

      Re: Hiding mouse cursor in QML

      Tried both solutions given in this thread separately but they don't seem to do anything to the display, a pointer always shows up at the top left of the display. Other solutions attempted are creating a mouse area under the window and blanking that cursor, but I don't even have a mouse plugged in and will strictly use a touch screen.

      Here is my main.qml:

      import QtQuick
      import QtQuick.Window 2.15
      import QtQuick.Controls 2.0
      import io.qt.backend 1.0
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
          HoverHandler {
              id: mouse
              cursorShape: Qt.BlankCursor
          }
      }
      

      and main.cpp

      #include <QGuiApplication>
      
      #include <QQmlApplicationEngine>
      
      
      int main(int argc, char *argv[])
      {
          if (qEnvironmentVariableIsEmpty("QTGLESSTREAM_DISPLAY")) {
              qputenv("QT_QPA_EGLFS_PHYSICAL_WIDTH", QByteArray("213"));
              qputenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT", QByteArray("120"));
      
      #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
              QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      #endif
          }
          QGuiApplication app(argc, argv);
          QGuiApplication::setOverrideCursor;
      
          QQmlApplicationEngine engine;
          const QUrl url(QStringLiteral("qrc:/main.qml"));
          QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
              &app, [url](QObject *obj, const QUrl &objUrl) {
                  if (!obj && url == objUrl)
                      QCoreApplication::exit(-1);
              }, Qt::QueuedConnection);
          engine.load(url);
      
          return app.exec();
      }
      

      for this second solution I get warning: statement has no effect [-Wunused-value]

      using qt 6.5, ubuntu,

      GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      @hazbody21 QGuiApplication::setOverrideCursor is a function.

      H 1 Reply Last reply
      1
      • GrecKoG GrecKo

        @hazbody21 QGuiApplication::setOverrideCursor is a function.

        H Offline
        H Offline
        hazbody21
        wrote on last edited by
        #3

        @GrecKo
        Thank you for the clarification. Adding

        QGuiApplication::setOverrideCursor(QCursor(Qt::BlankCursor));
        

        works

        1 Reply Last reply
        0
        • H hazbody21 has marked this topic as solved on

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved