Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Set waitcursor on qtextedit



  • By default in a Qt GUI app the cursor changes to an IBeam when the mouse moves over a textedit. How can I change it to a waitcursor? I can set the waitcursor to the whole app but that is not what I need. I want to keep the arrow cursor except when the mouse cursor moves over textedit.

    This is what I have tried with no luck.

    @ def run_process(self):
    self.textEdit.setCursor(Qt.WaitCursor)
    self.textEdit.clear()
    self.textEdit.append("Standby, this proc takes time.")
    QApplication.processEvents()
    process = subprocess.Popen(['ext_proc.sh'], stdout=subprocess.PIPE)
    results = process.communicate()[0]
    self.textEdit.clear()
    self.textEdit.append(results)
    self.textEdit.setCursor(Qt.IBeamCursor)@



  • The cursor is being set by the QTextEdit's viewport, not the QTextEdit itself. Try the following:

    @
    from PyQt4.QtCore import *
    from PyQt4.QtGui import *

    if name=="main":
    from sys import argv, exit

    class Widget(QWidget):
        def __init__(self, parent=None, **kwargs):
            QWidget.__init__(self, parent, **kwargs)
    
            l=QVBoxLayout(self)
    
            t=QTextEdit()
            t.viewport().setCursor(Qt.WaitCursor)
            l.addWidget(t)
    
    a=QApplication(argv)
    w=Widget()
    w.show()
    w.raise_()
    exit(a.exec_())
    

    @

    Hope this helps ;o)



  • I used the following and it changed to cursor over the textwidget to an arrow until the process finished and then set it back to an Ibeam.

    @ def run_process(self):
    self.textEdit.viewport().setCursor(Qt.WaitCursor)
    self.textEdit.clear()
    self.textEdit.append("Standby, this proc takes time.")
    QApplication.processEvents()
    process = subprocess.Popen(['ext_proc.sh'], stdout=subprocess.PIPE)
    results = process.communicate()[0]
    self.textEdit.clear()
    self.textEdit.append(results)
    self.textEdit.viewport().setCursor(Qt.IBeamCursor)@



  • The cursor changes to an arrow even if I comment out my setCursor commands. That tells me that the cursor setting is getting over ridden.

    As a test I set WaitCursor on textEdit in the init function and sure enough it shows up. As soon as I start the subprocess it turns into an arrow until the subprocess is done.

    My cursor setting is getting over ridden but I'm not sure why or how.



  • Switch to QProcess, which is what I intended to use from the start, and had some success.

    I can now set the wait cursor for the textWidget only.

    @def run_process(self):
    self.textEdit.viewport().setCursor(Qt.WaitCursor)
    self.textEdit.clear()
    self.textEdit.append("Standby, this proc takes time.")
    self.runner = QProcess(self)
    self.runner.readyReadStandardOutput.connect(self.GetStd)
    self.runner.start('ext_proc.sh')

    def GetStd(self)
    StdOut = str(self.runner.readAllStandardOutput())
    self.textEdit.append(StdOut)
    self.textEdit.viewport().setCursor(Qt.IBeamCursor@

    The problem now is that the Ibeam cursor is reset upon the first input of standard out. However, ext_proc.sh is still running.

    Tried some things with waitForFinished() but it froze the interface.

    Is there a way to keep the wait cursor until the external process is complete without locking the GUI?

    Thanks in advance,
    Cheers,


Log in to reply