2

I have a small Qt application that displays an image to the screen (more on that including source code here: Qt: Modify alpha channel transparency of a windowless QLabel).

By default, Qt is inserting a mouse pointer on top of my image. For my application, I do not need any physical user interaction with Qt and thus have no need for a mouse pointer.

I have used the following code to hide the mouse pointer, but it only hides the mouse once the mouse has been physically moved, and only within the displayed image. If my image is smaller than the display area, I can freely move the mouse pointer through this space.

int main (int argc, char *argv[])
{
    QApplication app(argc, argv);

    // Try to hide the cursor
    app.setOverrideCursor(QCursor(Qt::BlankCursor));

    return app.exec();
}

How can I hide the mouse pointer when I start my application without the need to actually move the mouse?

I am running Qt version 4.8.4 on my embedded deivce.

(Also, I am running my application without a QWidget window. So I am looking for solutions that does not require this).

jww
  • 97,681
  • 90
  • 411
  • 885
Josh Kurland
  • 197
  • 1
  • 3
  • 12
  • Also see [Hide cursor in fullscreen mode using Qt 4.8?](https://stackoverflow.com/q/19930794/608639) – jww Dec 10 '19 at 20:38

2 Answers2

2

Try this code :

app.setCursorVisible(false);

or this :

app.setOverrideCursor(Qt::BlankCursor);
  • Thank you, but neither of these solutions work. The class QApplication has no member named 'setCursorVisible'. Also, setOverrideCursor has the prototype QGuiApplication::setOverrideCursor(const QCursor &cursor). I am pretty sure that what you provided here is equivalent to what I had posted above. Regardless, it does not remove the cursor when the application is started. – Josh Kurland May 16 '17 at 17:03
  • @JoshKurland these codes makes mistake? or got compile error? – BattleTested_закалённый в бою May 16 '17 at 17:04
  • setCursorVisible is not available to the QApplication class in Qt 4.8. However, it is available to the QWSServer class, (http://doc.qt.io/qt-4.8/qwsserver.html#setCursorVisible). Regretfully this will not work within my application. – Josh Kurland May 16 '17 at 17:10
  • @JoshKurland takw a look at this [link](http://www.programering.com/a/MjMwEjMwATk.html). may can help you. – BattleTested_закалённый в бою May 16 '17 at 17:37
  • I used 'app.setOverrideCursor(Qt::BlankCursor);' in Qt 5.12.12 in a Raspberry Pi 2 EGLFS Qt app and it worked. – Bjorn Mar 08 '22 at 21:40
2

I found a command line option, "-nomouse", that seems to do the trick. It is not my ideal solution, but it works for now.

$ ./my-Qt-application -nomouse

http://doc.qt.io/qt-4.8/qt-embedded-running.html (search for -nomouse under the Command Line options)

Josh Kurland
  • 197
  • 1
  • 3
  • 12