Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Mouse cursor shape

    QML and Qt Quick
    2
    4
    2319
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mivoligo last edited by

      How can I change the shape of the cursor in QML?

      1 Reply Last reply Reply Quote 0
      • M
        Macro last edited by

        Check this link "MouseArea Element Reference":http://qt-project.org/doc/qt-4.7/qml-mousearea.html U'll get an idea about it.

        Note: Check the Doc Notes in it.

        1 Reply Last reply Reply Quote 0
        • M
          mivoligo last edited by

          Thanks for your answer.
          Actually I was trying to implement what is described there before but get lots of errors. When I'll be back to my computer, I'll post what problem I had.

          1 Reply Last reply Reply Quote 0
          • M
            mivoligo last edited by

            OK, I have following errors:
            @../supertest/main.cpp: In function 'int main(int, char**)':
            ../supertest/main.cpp:9:21: error: 'CursorShapeArea' was not declared in this scope
            ../supertest/main.cpp:9:72: error: no matching function for call to 'qmlRegisterType(const char [8], int, int, const char [16])'
            ../supertest/main.cpp:9:72: note: candidates are:
            /usr/include/qt4/QtDeclarative/qdeclarative.h:90:5: note: template<class T> int qmlRegisterType()
            /usr/include/qt4/QtDeclarative/qdeclarative.h:160:5: note: template<class T> int qmlRegisterType(const char*, int, int, const char*)
            /usr/include/qt4/QtDeclarative/qdeclarative.h:194:5: note: template<class T, int metaObjectRevision> int qmlRegisterType(const char*, int, int, const char*)@

            My cursorshapearea.cpp file:
            @
            #include "cursorshapearea.h"

            QsltCursorShapeArea::QsltCursorShapeArea(QDeclarativeItem *parent) :
            QDeclarativeItem(parent),
            m_currentShape(-1)
            {
            }

            Qt::CursorShape QsltCursorShapeArea::cursorShape() const
            {
            return cursor().shape();
            }

            void QsltCursorShapeArea::setCursorShape(Qt::CursorShape cursorShape)
            {
            if (m_currentShape == (int) cursorShape)
            return;

            setCursor(cursorShape);
            emit cursorShapeChanged();

            m_currentShape = cursorShape;
            }@

            My cursorshapearea.h file:

            @#ifndef CURSORSHAPEAREA_H
            #define CURSORSHAPEAREA_H

            #include <QDeclarativeItem>

            class QsltCursorShapeArea : public QDeclarativeItem
            {
            Q_OBJECT

            Q_PROPERTY(Qt::CursorShape cursorShape READ cursorShape WRITE setCursorShape NOTIFY cursorShapeChanged)

            public:

            explicit QsltCursorShapeArea(QDeclarativeItem *parent = 0);

            Qt::CursorShape cursorShape() const;
            Q_INVOKABLE void setCursorShape(Qt::CursorShape cursorShape);

            private:
            int m_currentShape;

            signals:
            void cursorShapeChanged();
            };

            #endif // CURSORSHAPEAREA_H
            @

            main.cpp file:
            @#include <QtGui/QApplication>
            #include "qmlapplicationviewer.h"
            #include <QtDeclarative>
            #include "cursorshapearea.h"

            Q_DECL_EXPORT int main(int argc, char *argv[])
            {
            QScopedPointer<QApplication> app(createApplication(argc, argv));
            qmlRegisterType<CursorShapeArea>("MyTools", 1, 0, "CursorShapeArea");
            QmlApplicationViewer viewer;
            viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
            viewer.setMainQmlFile(QLatin1String("qml/supertest/main.qml"));
            viewer.showExpanded();

            return app->exec&#40;&#41;;
            

            }
            @

            main.qml file:
            @// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
            import QtQuick 1.1
            import MyTools 1.0
            Rectangle {
            width: 360
            height: 360
            Text {
            text: qsTr("Hello World")
            anchors.centerIn: parent
            }
            MouseArea {
            anchors.fill: parent
            onClicked: {
            Qt.quit();
            }
            }
            }
            @

            1 Reply Last reply Reply Quote 0
            • First post
              Last post