Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. textEdit takes 4 seconds to show up the text
Qt 6.12 LTS is out! See what's new in the release blog

textEdit takes 4 seconds to show up the text

Scheduled Pinned Locked Moved Solved Qt for Python
19 Posts 3 Posters 7.2k Views 1 Watching
  • 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.
  • JonBJ JonB

    @adrian88888888
    There is nothing wrong with your code. Try giving your text edit an explicit, bigger height (and width) in case it's some scrolling issue.

    You're not really supposed to just slap widgets onto a QMainWindow. It has a complicated layout. I wonder if that's the issue. Try adding your line edit onto its central layout, with a proper layout.

    A Offline
    A Offline
    adrian88888888
    wrote on last edited by adrian88888888
    #3

    @JonB I change the dimensions of the textEdit and put it inside a frame and layout, it keeps having the delay:

    alt text

    I realised that when i preview it inside Qt Designer(I use it to make the gui's) it does not lag:

    alt text

    From the moment I transform the Qt Designer project into a .py file, to the moment I execute the .py file, the problem it's generated

    .------------------------------------------------------------------

    just in case I leave here the code that Qt Designer "makes":

    # -*- coding: utf-8 -*-
    
    ################################################################################
    ## Form generated from reading UI file 'mini_consola.ui'
    ##
    ## Created by: Qt User Interface Compiler version 5.15.0
    ##
    ## WARNING! All changes made in this file will be lost when recompiling UI file!
    ################################################################################
    
    from PySide2.QtCore import (QCoreApplication, QDate, QDateTime, QMetaObject,
        QObject, QPoint, QRect, QSize, QTime, QUrl, Qt)
    from PySide2.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont,
        QFontDatabase, QIcon, QKeySequence, QLinearGradient, QPalette, QPainter,
        QPixmap, QRadialGradient)
    from PySide2.QtWidgets import *
    
    
    class Ui_MainWindow(object):
        def setupUi(self, MainWindow):
            if not MainWindow.objectName():
                MainWindow.setObjectName(u"MainWindow")
            MainWindow.resize(665, 22)
            self.centralwidget = QWidget(MainWindow)
            self.centralwidget.setObjectName(u"centralwidget")
            self.verticalLayout = QVBoxLayout(self.centralwidget)
            self.verticalLayout.setSpacing(0)
            self.verticalLayout.setObjectName(u"verticalLayout")
            self.verticalLayout.setContentsMargins(0, 0, 0, 0)
            self.frame = QFrame(self.centralwidget)
            self.frame.setObjectName(u"frame")
            self.frame.setFrameShape(QFrame.StyledPanel)
            self.frame.setFrameShadow(QFrame.Raised)
            self.gridLayout = QGridLayout(self.frame)
            self.gridLayout.setSpacing(0)
            self.gridLayout.setObjectName(u"gridLayout")
            self.gridLayout.setContentsMargins(0, 0, 0, 0)
            self.textEdit_MiniConsola = QLineEdit(self.frame)
            self.textEdit_MiniConsola.setObjectName(u"textEdit_MiniConsola")
            self.textEdit_MiniConsola.setStyleSheet(u"font: 20pt \"MS Shell Dlg 2\";")
    
            self.gridLayout.addWidget(self.textEdit_MiniConsola, 0, 0, 1, 1)
    
    
            self.verticalLayout.addWidget(self.frame)
    
            MainWindow.setCentralWidget(self.centralwidget)
    
            self.retranslateUi(MainWindow)
    
            QMetaObject.connectSlotsByName(MainWindow)
        # setupUi
    
        def retranslateUi(self, MainWindow):
            MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None))
        # retranslateUi
    
    

    And the main.py just in case:

    import sys
    from PySide2 import QtCore, QtGui, QtWidgets
    from PySide2.QtCore import *
    from PySide2.QtGui import *
    from PySide2.QtWidgets import *
    
    from mini_consola import Ui_MainWindow
    # mini_consola.py has all the stuff made by Qt Desginer
    
    class MainWindow(QMainWindow):
        def __init__(self):
            QMainWindow.__init__(self)
            self.ui = Ui_MainWindow()
            self.ui.setupUi(self)
    
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        window = MainWindow()
        window.show()
        sys.exit(app.exec_())
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      Hi,

      You should add some system information like Qt version, OS, machine type etc.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        You should add some system information like Qt version, OS, machine type etc.

        A Offline
        A Offline
        adrian88888888
        wrote on last edited by adrian88888888
        #5

        @SGaist
        PyQt version = 5.13.2
        OS: Windows 10 x64
        I don't know what else to give
        Python: 3.8.5
        If you need something else, tell me

        Edit: Qt version: 5.13.2

        JonBJ 1 Reply Last reply
        0
        • A adrian88888888

          @SGaist
          PyQt version = 5.13.2
          OS: Windows 10 x64
          I don't know what else to give
          Python: 3.8.5
          If you need something else, tell me

          Edit: Qt version: 5.13.2

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #6

          @adrian88888888
          You give your PyQt version but not your Qt version. Make sure they are consistent.

          To simplify your situation you can create an app which is only a QLineEdit. No QMainWindow, no layouts. E.g replace your window = MainWindow() by window = QLineEdit(). Any different behaviour?

          A 1 Reply Last reply
          0
          • JonBJ JonB

            @adrian88888888
            You give your PyQt version but not your Qt version. Make sure they are consistent.

            To simplify your situation you can create an app which is only a QLineEdit. No QMainWindow, no layouts. E.g replace your window = MainWindow() by window = QLineEdit(). Any different behaviour?

            A Offline
            A Offline
            adrian88888888
            wrote on last edited by
            #7

            @JonB Yes I can simplify it more, i didn't knew I could replace window = MainWindow() by window = QLineEdit()

            This is the code as simplified as possible:

            import sys
            from PySide2.QtWidgets import *
            
            app = QApplication(sys.argv)
            window = QLineEdit()
            window.show()
            sys.exit(app.exec_())
            

            and the delay keeps being there, can you run this simple code and check out the fact that is not my system?

            Qt version: 5.13.2
            you mean that the versions have to be the same all the time(Qt and PyQt)?

            JonBJ 1 Reply Last reply
            0
            • A adrian88888888

              @JonB Yes I can simplify it more, i didn't knew I could replace window = MainWindow() by window = QLineEdit()

              This is the code as simplified as possible:

              import sys
              from PySide2.QtWidgets import *
              
              app = QApplication(sys.argv)
              window = QLineEdit()
              window.show()
              sys.exit(app.exec_())
              

              and the delay keeps being there, can you run this simple code and check out the fact that is not my system?

              Qt version: 5.13.2
              you mean that the versions have to be the same all the time(Qt and PyQt)?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #8

              @adrian88888888 said in textEdit takes 4 seconds to show up the text:

              you mean that the versions have to be the same all the time(Qt and PyQt)?

              It helps :) Your are anyway.

              No, this won't happen to the rest of us. A time delay every time we type characters into a QLineEdit? I think we would notice.

              If you can, try this in PyQt5 in case it's ...

              WAIT!! You say you are using PyQt

              PyQt version = 5.13.2

              but you are

              from PySide2.QtWidgets import *
              

              Do you think this might be why you have a problem? :D

              A 1 Reply Last reply
              0
              • JonBJ JonB

                @adrian88888888 said in textEdit takes 4 seconds to show up the text:

                you mean that the versions have to be the same all the time(Qt and PyQt)?

                It helps :) Your are anyway.

                No, this won't happen to the rest of us. A time delay every time we type characters into a QLineEdit? I think we would notice.

                If you can, try this in PyQt5 in case it's ...

                WAIT!! You say you are using PyQt

                PyQt version = 5.13.2

                but you are

                from PySide2.QtWidgets import *
                

                Do you think this might be why you have a problem? :D

                A Offline
                A Offline
                adrian88888888
                wrote on last edited by adrian88888888
                #9

                @JonB but i'm not supposed to use PySide2 in order to use Qt in python? as i understand pyside2 its the intermediate between qt and python?

                or i'm all wrong?

                now that you say, PyQt has a py in front for some reason, omg tell me that's it

                what i'm supposed to import then?

                oh no, this has a delay too:

                import sys
                from PyQt5.QtWidgets import *
                
                app = QApplication(sys.argv)
                window = QLineEdit()
                window.show()
                sys.exit(app.exec_())
                
                JonBJ 1 Reply Last reply
                0
                • A adrian88888888

                  @JonB but i'm not supposed to use PySide2 in order to use Qt in python? as i understand pyside2 its the intermediate between qt and python?

                  or i'm all wrong?

                  now that you say, PyQt has a py in front for some reason, omg tell me that's it

                  what i'm supposed to import then?

                  oh no, this has a delay too:

                  import sys
                  from PyQt5.QtWidgets import *
                  
                  app = QApplication(sys.argv)
                  window = QLineEdit()
                  window.show()
                  sys.exit(app.exec_())
                  
                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #10

                  @adrian88888888
                  Not that any of the rest of us have it. But is this delay only if you rapidly type a few characters, or is it equally if you just type one character? And not in any other application, like Notepad?

                  A 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @adrian88888888
                    Not that any of the rest of us have it. But is this delay only if you rapidly type a few characters, or is it equally if you just type one character? And not in any other application, like Notepad?

                    A Offline
                    A Offline
                    adrian88888888
                    wrote on last edited by
                    #11

                    @JonB it is the same delay, doesn't matter what i type, i can type one letter and the delay its 4 seconds too

                    the delay happens at the first time i write in the textEdit, if i delete the text and start writing again the delay its gone

                    this happens only in this application, does not happen in notepad or others

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @adrian88888888 said in textEdit takes 4 seconds to show up the text:

                      @JonB but i'm not supposed to use PySide2 in order to use Qt in python? as i understand pyside2 its the intermediate between qt and python?

                      PyQt is a different project that existed long before PySide2. It is also provided by a different company under a different set of licences.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        adrian88888888
                        wrote on last edited by
                        #13

                        i got no idea what to do, i reduced the problem to his minimum escence:

                        import sys
                        from PyQt5.QtWidgets import *
                        
                        app = QApplication(sys.argv)
                        window = QLineEdit()
                        window.show()
                        sys.exit(app.exec_())
                        

                        what is the next step? i should report this as a bug? but i don't know if its a bug

                        can someone run this code and see? so i can uncheck the fact that i'm not crazy

                        at least i could know if its only me

                        JonBJ 1 Reply Last reply
                        0
                        • A adrian88888888

                          i got no idea what to do, i reduced the problem to his minimum escence:

                          import sys
                          from PyQt5.QtWidgets import *
                          
                          app = QApplication(sys.argv)
                          window = QLineEdit()
                          window.show()
                          sys.exit(app.exec_())
                          

                          what is the next step? i should report this as a bug? but i don't know if its a bug

                          can someone run this code and see? so i can uncheck the fact that i'm not crazy

                          at least i could know if its only me

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #14

                          @adrian88888888
                          Realistically: You would be best to uninstall everything, Qt itself in particular, both PyQt5 and PySide2. Reinstall from scratch. And/or, try on another PC.

                          By all means what and see if anyone else is reporting that QLineEdits have a 4 second delay.

                          A 1 Reply Last reply
                          0
                          • JonBJ JonB

                            @adrian88888888
                            Realistically: You would be best to uninstall everything, Qt itself in particular, both PyQt5 and PySide2. Reinstall from scratch. And/or, try on another PC.

                            By all means what and see if anyone else is reporting that QLineEdits have a 4 second delay.

                            A Offline
                            A Offline
                            adrian88888888
                            wrote on last edited by adrian88888888
                            #15

                            @JonB I tried in another pc and it's the same problem, I will see in the bug reports or something

                            JonBJ 1 Reply Last reply
                            0
                            • A adrian88888888

                              @JonB I tried in another pc and it's the same problem, I will see in the bug reports or something

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by
                              #16

                              @adrian88888888
                              It would mean that the simplest Qt line edit program has a delay for everyone. Which would have been noticed.

                              It is just possible that something is going on in the background while your program is still initializing, if you are typing into this line edit the moment you see the window. If you wait a few seconds before typing your first character, is there still a delay? It's mystifying :)

                              A 1 Reply Last reply
                              0
                              • JonBJ JonB

                                @adrian88888888
                                It would mean that the simplest Qt line edit program has a delay for everyone. Which would have been noticed.

                                It is just possible that something is going on in the background while your program is still initializing, if you are typing into this line edit the moment you see the window. If you wait a few seconds before typing your first character, is there still a delay? It's mystifying :)

                                A Offline
                                A Offline
                                adrian88888888
                                wrote on last edited by adrian88888888
                                #17

                                @JonB Yes it's really mystifying

                                The answer it's: the delay keeps being there
                                alt text

                                No one would noticed this, because no one has a program with just a textEdit, in my case I want that

                                I will see, Idk, pray for me :P

                                JonBJ 1 Reply Last reply
                                0
                                • A adrian88888888

                                  @JonB Yes it's really mystifying

                                  The answer it's: the delay keeps being there
                                  alt text

                                  No one would noticed this, because no one has a program with just a textEdit, in my case I want that

                                  I will see, Idk, pray for me :P

                                  JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote on last edited by
                                  #18

                                  @adrian88888888
                                  To keep you happy, I tried this on my system --- Ubuntu 20.04 (I think you are Windows), PyQt version: 5.14.1, Qt version: 5.12.8. I also tested with PySide2. As expected they behave fine, no delay.

                                  Try this little piece of code:

                                  import sys
                                  from PyQt5.QtWidgets import *
                                  
                                  def textEdited():
                                    print("Text edited")
                                  
                                  if __name__ == '__main__':
                                    app = QApplication(sys.argv)
                                    window = QLineEdit()
                                    window.textEdited.connect(textEdited)
                                    window.show()
                                    sys.exit(app.exec_())
                                  

                                  If you run this from a Command Prompt --- python path-to-your-file.py --- it will print Text edited as soon as it detects a character press in your QLineEdit. For me that of course is immediate. What about for you? This distinguishes between when Qt sees the key press versus if there is some issue updating the QLineEdit to show the character, if there is any discrepancy.

                                  The fact that you have "only* a QTextEdit should be neither here nor there. Of course you can build a more complex situation, but from what you showed earlier one would think you will have the same problem wherever you use a QLineEdit.

                                  If you hadn't said you have tried on another PC and found same problem I would have said it was your PC. Since your problem occurs under both PyQt5 & PySide2 I would assume your problem lies in the Qt, or even the windowing system, not in the Python side. You presumably installed the same Qt version on both PCs? Can you try installing some other version of Qt to test?

                                  A 1 Reply Last reply
                                  2
                                  • JonBJ JonB

                                    @adrian88888888
                                    To keep you happy, I tried this on my system --- Ubuntu 20.04 (I think you are Windows), PyQt version: 5.14.1, Qt version: 5.12.8. I also tested with PySide2. As expected they behave fine, no delay.

                                    Try this little piece of code:

                                    import sys
                                    from PyQt5.QtWidgets import *
                                    
                                    def textEdited():
                                      print("Text edited")
                                    
                                    if __name__ == '__main__':
                                      app = QApplication(sys.argv)
                                      window = QLineEdit()
                                      window.textEdited.connect(textEdited)
                                      window.show()
                                      sys.exit(app.exec_())
                                    

                                    If you run this from a Command Prompt --- python path-to-your-file.py --- it will print Text edited as soon as it detects a character press in your QLineEdit. For me that of course is immediate. What about for you? This distinguishes between when Qt sees the key press versus if there is some issue updating the QLineEdit to show the character, if there is any discrepancy.

                                    The fact that you have "only* a QTextEdit should be neither here nor there. Of course you can build a more complex situation, but from what you showed earlier one would think you will have the same problem wherever you use a QLineEdit.

                                    If you hadn't said you have tried on another PC and found same problem I would have said it was your PC. Since your problem occurs under both PyQt5 & PySide2 I would assume your problem lies in the Qt, or even the windowing system, not in the Python side. You presumably installed the same Qt version on both PCs? Can you try installing some other version of Qt to test?

                                    A Offline
                                    A Offline
                                    adrian88888888
                                    wrote on last edited by adrian88888888
                                    #19

                                    @JonB You are being too generous with me for helping me all the way, i don't want to take more of your efforts

                                    I just added some text and deleted it in the first run of the program, like this:

                                    self.ui.textEdit.setText('hello world')
                                    self.ui.textEdit.setText('')
                                    

                                    and the delay its gone with that

                                    If for some reason if i need to fix this i will come back to it, but i really hope really bad to not have to fix this(because is so hard to troubleshoot)

                                    Btw it looks that its something related with windows 10 because in your ubuntu works and i tried in 2 windows 10 machines and didn't work

                                    printing "Text edited" has delay too

                                    1 Reply Last reply
                                    1

                                    • Login

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