Very small issue:
I've written a small IDE with a text editing widget based on a QPlainTextEdit. When you move the mouse over it the cursor becomes a caret/text cursor as expected. If you hit F5 the window is disabled and a small script runs after which the window is re-enabled and the text area is given focus.
Somehow, this changes the cursor from a text cursor to a pointer. If you move the cursor off the text area and then back onto it, it turns into a text cursor again.
Is there some way to trigger this refresh action programmatically?
Update: It seems to be something to do with having a progress bar:
#!/usr/bin/env python
import sys
import time
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import Qt
class TinyIDE(QtGui.QMainWindow):
def __init__(self, filename=None):
super(TinyIDE, self).__init__()
self.setWindowTitle('Tiny IDE test')
# Add menu item
menu = self.menuBar()
menu_run = menu.addMenu('&Run')
tool_run = QtGui.QAction('&Run', self)
tool_run.setShortcut('F5')
tool_run.triggered.connect(self.action_run)
menu_run.addAction(tool_run)
# Add editor
self._editor = QtGui.QPlainTextEdit()
self._editor.setPlainText('Press F5 to run')
self.setCentralWidget(self._editor)
self._editor.setFocus()
def action_run(self):
pbar = None
try:
self.setEnabled(False)
pbar = QtGui.QProgressDialog('Running script', 'Cancel', 0, 10)
pbar.setWindowModality(Qt.WindowModal)
pbar.setAutoClose(False)
pbar.setAutoReset(False)
pbar.show()
for i in xrange(10):
time.sleep(0.2)
pbar.setValue(1 + i)
QtGui.QApplication.processEvents()
finally:
QtGui.QApplication.processEvents()
pbar.close()
pbar.deleteLater()
self.setEnabled(True)
self._editor.setFocus()
if __name__ == '__main__':
a = QtGui.QApplication([])
a.connect(a, QtCore.SIGNAL('lastWindowClosed()'), a, QtCore.SLOT('quit()'))
w = TinyIDE()
w.show()
sys.exit(a.exec_())
I've tested it on Linux (Fedora 21) with Python 2.7.8 and PyQt4 version 4.8.6
Steps to reproduce:
- Run the script
- Place the mouse cursor over the text area, it should turn into a text cursor
- Press F5, wait for the progress bar to go away, leave the mouse hovering over the text area, it should turn into a pointer
Expected result: Once the progress bar goes away the cursor, still hovering over the text area, should revert to a text cursor
Actual result: The cursor stays a pointer, until it's moved off and back on to the text area
QtGui.QApplication.setOverrideCursor(QtGui.QCursor(Qt.WaitCursor))
when you callaction_run()
. When it's over, restore to your original mouse cursor withQtGui.QApplication.restoreOverrideCursor()
. – Ewerself._editor.setCursor(Qt.UpArrowCursor)
changes anything? On my computer, this is not working as I expect, the cursor is only changed for the "borders" of the widget. I suspectQPlainTextEdit
to overwrite the mouse cursor on the editor. However, when I create the same UI in Qt Designer and change the cursor in it, the mouse cursor is properly overwrited, weird. You can restore the original cursor withself._editor.unsetCursor()
. – EwerThe shape of the mouse cursor on a PySide.QtGui.QPlainTextEdit is Qt.IBeamCursor by default. It can be changed through the PySide.QtGui.QAbstractScrollArea.viewport() ‘s cursor property.
Maybe an interesting track to follow. – Ewerself._editor.viewport().setCursor(Qt.UpArrowCursor)
? First try using it in your UI creation without the global QApplication mouse cursor overwrite. If it's not working as expected, try mixing everything. – Ewer