Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the cursor shape with PyQt?

Tags:

I have a simple application that runs a process that can last for several minutes before completing. I am trying to provide an indication to the user that it is processing the request - such as changing the cursor to an hourglass.

But I cannot quite get it to work right. All of my attempts have resulted in either an error or had no effect. And I seem to be calling the cursor shapes incorrectly, since PyQt4.Qt.WaitCursor returns an error that the module does not contain it.

What is the correct way to indicate to the user that the process is running?

like image 347
TimothyAWiseman Avatar asked Nov 21 '11 21:11

TimothyAWiseman


People also ask

How do I change the shape of my cursor in Qt?

To set a cursor shape use QCursor::setShape() or use the QCursor constructor which takes the shape as argument, or you can use one of the predefined cursors defined in the Qt::CursorShape enum.

What shape is a cursor?

The most commonly used cursor shape is an arrow.

What is cursor in GUI?

1) A cursor is the position indicator on a computer display screen where a user can enter text. In an operating system with a graphical user interface (GUI), the cursor is also a visible and moving pointer that the user controls with a mouse, touch pad, or similar input device.


1 Answers

I think QApplication.setOverrideCursor is what you're looking for:

PyQt5:

from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QApplication ... QApplication.setOverrideCursor(Qt.WaitCursor) # do lengthy process QApplication.restoreOverrideCursor() 

PyQt4:

from PyQt4.QtCore import Qt from PyQt4.QtGui import QApplication ... QApplication.setOverrideCursor(Qt.WaitCursor) # do lengthy process QApplication.restoreOverrideCursor() 
like image 104
ekhumoro Avatar answered Nov 02 '22 10:11

ekhumoro