Change Mouse Cursor
-
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 -
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.
-
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 -
-
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");
}
}@ -
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