Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Set waitcursor on qtextedit
QtWS25 Last Chance

Set waitcursor on qtextedit

Scheduled Pinned Locked Moved Language Bindings
5 Posts 2 Posters 3.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Blackbear
    wrote on last edited by
    #1

    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)@

    1 Reply Last reply
    0
    • jazzycamelJ Offline
      jazzycamelJ Offline
      jazzycamel
      wrote on last edited by
      #2

      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)

      For the avoidance of doubt:

      1. All my code samples (C++ or Python) are tested before posting
      2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
      1 Reply Last reply
      0
      • B Offline
        B Offline
        Blackbear
        wrote on last edited by
        #3

        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)@

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Blackbear
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Blackbear
            wrote on last edited by
            #5

            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,

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved