title: PyQt5: How to set a custom mouse pointer for each role?
body: <h2>1. Intro</h2>
  
  <p>I'm creating an application in <strong>Python 3.7</strong> with <strong>PyQt5</strong> for the GUI. I would like to customize the mouse cursors in the application.</p>
  
  <p>Let's start from the standard cursor set in <strong>Qt5</strong> as shown in a table here:
  <a href="https://doc.qt.io/qt-5/qt.html#CursorShape-enum" rel="noreferrer">https://doc.qt.io/qt-5/qt.html#CursorShape-enum</a>. You will notice that Qt5 has a dedicated Enum <code>Qt::CursorShape</code> describing the role of the corresponding cursor. For example:</p>
  
  <blockquote>
    <p><a href="https://i.stack.imgur.com/EhgnB.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/EhgnB.jpg" alt="Qt standard cursors"></a></p>
  </blockquote>
  
  <p>&nbsp;<br>
  I would like to replace each <strong>Standard Qt cursor</strong> with a <strong>custom</strong> made one:</p>
  
  <blockquote>
    <p><a href="https://i.stack.imgur.com/JkTwp.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/JkTwp.jpg" alt="Custom cursors"></a></p>
  </blockquote>
  
  <p>&nbsp;<br></p>
  
  <h2>2. First approach</h2>
  
  <p>At first I tried something like this:</p>
  
  <pre class="lang-py prettyprint-override"><code>pixmap = QPixmap("C:/../my_arrow.png")
  cursor = QCursor(pixmap, 32, 32)
  QApplication.setOverrideCursor(cursor)
  </code></pre>
  
  <p>Unfortunately, this approach is not good for my purpose. From the documentation:</p>
  
  <blockquote>
    <p>Application override cursors are intended for showing the user that <em>the application is in a special state</em>, for example during an operation that might take some time.<br>
    &nbsp;<br>
    The override cursor will be displayed in all the application's widgets until <code>restoreOverrideCursor()</code> or another <code>setOverrideCursor()</code> is called.</p>
  </blockquote>
  
  <p>In other words, using the <code>setOverrideCursor()</code> approach has two downsides:</p>
  
  <ol>
  <li><p>I would have to track manually to which role the mouse pointer should change, call <code>setOverrideCursor()</code> each time and feed it with the proper <code>QCursor()</code>.</p></li>
  <li><p>I'd need to track wherever Qt automatically calls <code>restoreOverrideCursor()</code>, because that effectively undoes my own changes. It would be a constant battle against Qt.</p></li>
  </ol>
  
  <p>&nbsp;<br></p>
  
  <h2>3. Second approach</h2>
  
  <p>My second approach was playing around with the <code>setCursor()</code> function:</p>
  
  <pre class="lang-py prettyprint-override"><code>pixmap = QPixmap("C:/../Arrow.png")
  cursor = QCursor(pixmap, 32, 32)
  my_widget.setCursor(cursor)
  </code></pre>
  
  <p>I do this on the toplevel widget - the <code>QMainWindow()</code> - such that the effect is applied on the whole application.</p>
  
  <p>It works great, but it has one downside. This function only changes the "default cursor" (the pointing arrow) but that's it. All the special cursors are still the same.</p>
  
  <p>&nbsp;<br>
  In fact, I would like to do something like this:</p>
  
  <pre class="lang-py prettyprint-override"><code># Note: 'mainwin' is the QMainWindow().
  mainwin.setCursor( QCursor(QPixmap("C:/../Arrow.png"),     32, 32), Qt.ArrowCursor     )
  mainwin.setCursor( QCursor(QPixmap("C:/../UpArrow.png"),   32, 32), Qt.UpArrowCursor   )
  mainwin.setCursor( QCursor(QPixmap("C:/../Cross.png"),     32, 32), Qt.CrossCursor     )
  mainwin.setCursor( QCursor(QPixmap("C:/../Wait.png"),      32, 32), Qt.WaitCursor      )
  mainwin.setCursor( QCursor(QPixmap("C:/../IBeam.png"),     32, 32), Qt.IBeamCursor     )
  mainwin.setCursor( QCursor(QPixmap("C:/../SizeVer.png"),   32, 32), Qt.SizeVerCursor   )
  mainwin.setCursor( QCursor(QPixmap("C:/../SizeHor.png"),   32, 32), Qt.SizeHorCursor   )
  mainwin.setCursor( QCursor(QPixmap("C:/../SizeBDiag.png"), 32, 32), Qt.SizeBDiagCursor )
  mainwin.setCursor( QCursor(QPixmap("C:/../SizeFDiag.png"), 32, 32), Qt.SizeFDiagCursor )
  ...
  </code></pre>
  
  <p>Unfortunately, that's not how the <code>setCursor()</code> function works.</p>
  
  <p>&nbsp;<br>
  Do you have a solution that matches best my purpose?</p>
  
  <p>&nbsp;</p>
  
  <h2>4. Resources</h2>
  
  <p>I've learned a lot from the following sources:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/25883457/default-mouse-icons-for-qt-applications">Default mouse icons for Qt applications</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/55455881/is-there-a-way-to-create-a-custom-animated-gif-qcursor">Is there a way to create a custom animated / gif QCursor?</a></p></li>
  </ul>
  
  <p>Unfortunately, none of them provided the solution to my problem. I just mention them here, because they are related to - but not the same as(!) - what I'm trying to do.</p>