Qt for embedded Linux: hide cursor at startup

I am developing a Qt application for the embedded Linux system. The system is equipped with a touch screen as well as an OTG USB port, and it can be used with the mouse.

So, my problem is that when the application starts, it shows the mouse cursor in the middle of the screen, and then disappears when the main event event occurs.

When the application starts, I can hide / show the cursor if the mouse is connected, which works fine, but there is always a cursor during startup.

I tried: QWSServer :: setCursorVisible (false);

or: qApp-> setOverrideCursor (QCursor (Qt :: BlankCursor));

and the result will be the same as described above.

The only way I found to hide the cursor at startup time was to compile Qt without a cursor, but then I cannot have the cursor when the mouse is connected (this logic ...).

So, if you have an idea, I will be happy to read it :-)

Thank you Sylvain

EDIT: Okey so that the QWS server displaying the cursor at startup detects that in qt / src / gui / embedded / qwscursor_qws.cpp:

void QWSServerPrivate::initializeCursor() { Q_Q(QWSServer); // setup system cursors #ifndef QT_NO_QWS_CURSOR // qt_screen->initCursor(sharedram + ramlen,true); // default cursor cursor = 0; setCursor(QWSCursor::systemCursor(Qt::ArrowCursor)); #endif q->sendMouseEvent(QPoint(swidth/2, sheight/2), 0); } 

Now, if I comment on the "setCursor" instruction, which solves the problem, but so ugly to edit the Qt source code to do this, so if you have a better solution ...

+4
source share
2 answers

This does not work with Qt5; but from the question, it seems like Qt4 with QWS . Code sequence

 QWSServer *server = QWSServer::instance(); if(server) { server->setCursorVisible(false); } 

will work with Qt4.x using QWS . It is important to note that only the server can do this. That is, the program is called using -qws . If you run multiple applications, clients will not be able to disable the cursor.

This should be done after creating QApplication , but before the first show () or showFullScreen (). You will probably try to do this before creating QApplication .

Edit: As you can see, when the application is initially displayed,

Add #define QT_NO_QWS_CURSOR 1 to the MyQconfig file and pass it ./configure with the -qconfig MyQconfig option -qconfig MyQconfig . Or you can use the qconfig graphical tool to configure Qt. qconfig is in the tools directory. The list of elements is in the src / corelib / global / qfeatures.txt file. See Fine tuning Qt for more details.

+6
source
 #include <QScreenCursor> QScreenCursor *cursor = new QScreenCursor; cursor->initSoftwareCursor(); cursor->hide(); 
+2
source

Source: https://habr.com/ru/post/1495277/


All Articles