Change Mouse Cursor
-
wrote on 10 Nov 2010, 00:09 last edited by
I'm trying to change the mouse cursor from QML.
Update: Cleared the content of this post by miss clicking. Sorry about that.
-
wrote on 10 Nov 2010, 00:36 last edited by
Hi,
That's correct, there isn't currently a cursor property (this is tracked by "QTBUG-10642":http://bugreports.qt.nokia.com/browse/QTBUG-10642).
In the above, I believe "this" actually refers to the global object -- try giving the rectangle an id and passing that to your function instead.
Regards,
Michael -
wrote on 10 Nov 2010, 09:42 last edited by
Hello mbrasser,
Updated my code to this:
@Rectangle {
id: toto
Component.onCompleted:
{
wView.setItemCursor(toto);
}
}@It appears I'm still getting an invalid pointer. I also tried changing my function prototype to QDeclarativeItem but that does not work either.
Any idea ?
Thanks.
B.A.
-
wrote on 10 Nov 2010, 23:12 last edited by
What version of Qt are you using? There was a bug at one point with QObject-derived function parameters, which should now be fixed (though I'm not sure if the fix was in 4.7.1 or coming in 4.7.2). If this is the issue you are running into, changing the function declaration to take a QObject* may work around it for you.
Regards,
Michael -
wrote on 18 May 2011, 06:28 last edited by
Sorry, I am a newbie to qt. I am trying to change the mouse cursor, from the point cursor to stretch cursor, when the mouse is over a MouseArea. Is this possible? I have read the above posts, but I don't understand what is going on,
Many thanks.
-
wrote on 18 May 2011, 09:01 last edited by
Hi Franziss,
This is currently not possible with the QML MouseArea.
You have to declare a QML QObject class with this function:
@/* Q_INVOKABLE */ void WControllerView::setItemCursor(QGraphicsObject * object, const QString & shape)
{
if (object == NULL)
{
qWarning("WControllerView::setItemCursor invalid QGraphicsObject");
return;
}if (shape == "") { object->unsetCursor(); return; } Qt::CursorShape cursor; if (shape == "PointingHandCursor") cursor = Qt::PointingHandCursor; else if (shape == "ArrowCursor") cursor = Qt::ArrowCursor; else if (shape == "IBeamCursor") cursor = Qt::IBeamCursor; else if (shape == "BlankCursor") cursor = Qt::BlankCursor;
// Add your "stretch cursor" here
else cursor = Qt::ArrowCursor;object->setCursor(cursor);
}@
Then call it from QML like this:
@Rectangle {
id: toto
Component.onCompleted:
{
wView.setItemCursor(toto, "YourCursorShape");
}
}@ -
wrote on 19 May 2011, 11:17 last edited by
Hi Bunjee,
Thank you very much for your code, it works! But I use slots instead of Q_INVOKABLE
Have a nice day!
-
wrote on 9 Dec 2011, 08:24 last edited by
Hi All
Many thanks for good idea.
But I try use this solution fot ListView delegate and got app crash. Have you any idea?
Sorry I newbie in Qt & QML -
wrote on 9 Dec 2011, 09:30 last edited by
You could use the example code here:
http://developer.qt.nokia.com/doc/qt-4.7/qml-mousearea.html
The Qt Quick Desktop components offer a very similar class, too.
Nils
-
wrote on 9 Dec 2011, 11:55 last edited by
Many thanks Nils!
Very good and clear example