问题
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