PDA

View Full Version : QCursor change shape in Qt 5



cic1988
4th March 2015, 07:48
Hello all,

my case is a bit rare but lets assume that in my application there is no standard QWindow or QWidget created, only the application is a QApplication.
I need to change the cursor shape in the runtime.

Without QWindow or QWidget i have no clue how can i change the cursor shape in Windows 7.
How can i do it with the help of Qt?

(Not with ::SetCursor(HCURSOR))

anda_skoa
4th March 2015, 08:03
Have you tried http://doc.qt.io/qt-5/qguiapplication.html#setOverrideCursor ?

Although without any window, there will be no space where you will see the changed cursor.

Cheers,
_

cic1988
4th March 2015, 08:18
No... the overridecursor works only when there is QWindow created from the source code in Qt 5.3.

anda_skoa
4th March 2015, 12:16
No... the overridecursor works only when there is QWindow created from the source code in Qt 5.3.

I don't see any error or warning when doing it in a minimal test program


#include <QtGui>

int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);

QGuiApplication::setOverrideCursor(QCursor(Qt::For biddenCursor));
qDebug() << "override cursor is" << QGuiApplication::overrideCursor()->shape() << "forbidden is" << Qt::ForbiddenCursor;
}

and the output suggest it worked

Cheers,
_

cic1988
4th March 2015, 17:43
I mean the QCursor has stored the shape of cursor, it is correct.
But the actual handle how it should look like or movement relies on the platform.

Have you seen this forbidden cursor on the screen when you run the code above?

ChrisW67
4th March 2015, 20:49
As anda_skoa said, there is no place you will see the Qt application cursor unless you have a visible window in your program.

If you want to manipulate the entire Windows mouse pointer theme, or do something to the mouse pointer system-wide then you have to resort to the Windows API.