Search code examples
c++qtcursor

How to change the cursor in Qt C++


How do I change the cursor to an image I have in the local machine? I have followed this tutorial for code reference: http://www.newthinktank.com/2018/07/qt-tutorial-5-paint-app/


Solution

  • Try this in your .qrc file:

    <RCC>
      <qresource prefix="/">
        <file>cursors/my_cursor.png</file>
      </qresource>
    </RCC>
    

    Then program this way:

    QPixmap p = QPixmap(":my_cursor");
    QCursor c = QCursor(p, 0, 0);
    setCursor(c);