Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt for Embedded Linux: Hide cursor on startup

I'm developing a Qt application on a linux embedded system. The system has got a touchscreen, but also an OTG USB port, and it must be usable with a mouse.

So my problem is, when the application starts, it shows a mouse cursor in the middle of the screen, and then it disapears when my main windows paint event occurs.

When the application has started, I can hide/show the cursor if a mouse is plugged in, that works great, but I always have the cursor during the startup.

I tried: QWSServer::setCursorVisible(false);

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

and the result is the same as described above.

The only way I found to hide the cursor during startup was compiling Qt without the Cursor, but then I can't have a cursor when the mouse is plugged in (that's logic...).

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

Thanks, Sylvain

EDIT: Okey so that's the QWS Server that shows the cursor on startup, I found 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 the "setCursor" instruction, that solves the problem, but that's kind of ugly to edit Qt source code to do that, so if you've got a better solution...

like image 312
Sylvain V Avatar asked Feb 16 '23 16:02

Sylvain V


2 Answers

This does not work with Qt5; but from the question this seems to be Qt4 with QWS. The code sequence,

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

will work with Qt4.x using QWS. An important point to note is that only the server may do this. Ie, the program invoked with -qws. If you run multiple applications, the clients will not be able to disable the cursor.

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

Edit: As you seem to mean when the application initially displays,

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

like image 91
artless noise Avatar answered Feb 19 '23 01:02

artless noise


#include <QScreenCursor>
QScreenCursor *cursor = new QScreenCursor;
cursor->initSoftwareCursor();
cursor->hide();
like image 31
DelHunter Avatar answered Feb 19 '23 03:02

DelHunter