Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Mouse cursor shape
Forum Updated to NodeBB v4.3 + New Features

Mouse cursor shape

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 2.6k Views 1 Watching
  • 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 Offline
    M Offline
    mivoligo
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Macro
      wrote on last edited by
      #2

      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
      0
      • M Offline
        M Offline
        mivoligo
        wrote on last edited by
        #3

        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
        0
        • M Offline
          M Offline
          mivoligo
          wrote on last edited by
          #4

          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
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved