Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide cursor in QML

Tags:

c++

qt

qml

qtquick2

I wonder how to hide cursor in QML, QT 5.7.

I tried to use

QGuiApplication::setOverrideCursor(QCursor(Qt::BlankCursor));

and

app.setOverrideCursor( QCursor( Qt::BlankCursor ) );

But both doesn't work.

/home/QTProjects/main.cpp:13: error: invalid use of incomplete type 'class QCursor'
     QGuiApplication::setOverrideCursor(QCursor(Qt::BlankCursor));
                                                               ^

And if it possible can I hide cursor within QML not on C++ side.

like image 902
Ruslan Skaldin Avatar asked Nov 26 '16 08:11

Ruslan Skaldin


People also ask

How do I hide my cursor in Qt?

we use QWSServer::setCursorVisible(false) to hide the cursor in qt 4.8 , which function in qt5?

What is mouse area in QML?

A MouseArea is an invisible item that is typically used in conjunction with a visible item in order to provide mouse handling for that item. By effectively acting as a proxy, the logic for mouse handling can be contained within a MouseArea item.


2 Answers

You can use a disabled overlay MouseArea to hide it:

  Button {
    onClicked: console.log("clicked")
  }

  MouseArea {
    anchors.fill: parent
    enabled: false
    cursorShape: Qt.BlankCursor
  }

Just put the mouse area in the bottom of your main.qml, it will be transparent to events but still override the cursor shape.

like image 56
dtech Avatar answered Sep 29 '22 02:09

dtech


you should include QCursor into main.cpp and call

QGuiApplication::setOverrideCursor(QCursor(Qt::BlankCursor));
like image 26
Mehdi Farhadi Avatar answered Sep 29 '22 01:09

Mehdi Farhadi