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
Forum Updated to NodeBB v4.3 + New Features

Hiding mouse cursor, qt quick

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 798 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 28 Jun 2023, 20:42 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,

    G 1 Reply Last reply 29 Jun 2023, 08:15
    0
    • H hazbody21
      28 Jun 2023, 20:42

      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,

      G Offline
      G Offline
      GrecKo
      Qt Champions 2018
      wrote on 29 Jun 2023, 08:15 last edited by
      #2

      @hazbody21 QGuiApplication::setOverrideCursor is a function.

      H 1 Reply Last reply 29 Jun 2023, 13:29
      1
      • G GrecKo
        29 Jun 2023, 08:15

        @hazbody21 QGuiApplication::setOverrideCursor is a function.

        H Offline
        H Offline
        hazbody21
        wrote on 29 Jun 2023, 13:29 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 29 Jun 2023, 13:29

        1/3

        28 Jun 2023, 20:42

        • Login

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