How to hide mouse pointer in Qt app at startup?

情到浓时终转凉″ 提交于 2020-02-05 03:47:45

问题


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).


回答1:


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)




回答2:


Try this code :

app.setCursorVisible(false);

or this :

app.setOverrideCursor(Qt::BlankCursor);


来源:https://stackoverflow.com/questions/44005653/how-to-hide-mouse-pointer-in-qt-app-at-startup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!