Qt::CursorShape + QML



  • Greetings Trolls,

    I would like to use the Qt enum CursorShape in my QML. Like this:
    @Component.onCompleted: {
    wView.setItemCursor(buttonMenuMouse, Qt.PointingHandCursor);
    }@

    Unfortunately when trying to I get the following error:

    bq. Error: Unknown method parameter type: Qt::CursorShape

    Is there a way to register Qt::CursorShape in my QML context or do I have to reimplement my own enum ?

    Thanks.

    B.A.



  • and what exactly is a wView object? if you register it manually you could implement a member function not using Qt::CursorShape type



  • bq. if you register it manually you could implement a member function not using Qt::CursorShape type

    Yes I could, but I would like to use Qt::CursorShape :).



  • Did this workaround:

    @Component.onCompleted: {
    wView.setItemCursor(boxMouseArea, "PointingHandCursor");
    }@

    And in the C++:

    @void WControllerView::setItemCursor(QGraphicsObject * object, const QString & shape)
    {
    Q_ASSERT(object);

    Qt::CursorShape cursor;
    
    if (shape == "PointingHandCursor") cursor = Qt::PointingHandCursor;
    else                               cursor = Qt::ArrowCursor;
    
    object->setCursor(QCursor(cursor));
    

    }@



  • that's exactly what I meant)



  • Not very sexy but it works :).

    Looks like the javascript is not a big fan of enums.



  • well that's no to so bad. you just need to register the type like other enums in QML are registered
    i've searched for it in declarative sources, and what i found is that you should use Q_ENUMS macro for registering enum type


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.