Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to run code written for PyQt4 in PyQt5

How to run code written for PyQt4 in PyQt5

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 1.3k 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.
  • J Offline
    J Offline
    john_hobbyist
    wrote on last edited by
    #1

    PyQt4 does not exist any more in Ubuntu 20.04. How can I run these examples: https://www.tutorialspoint.com/pyqt/pyqt_quick_guide.htm with PyQt5??

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

      Hi,

      Change PyQt4 for PyQt5 and move all widgets related import to QtWidgets in place of QtGui.

      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
      1
      • J Offline
        J Offline
        john_hobbyist
        wrote on last edited by
        #3

        In order to help me understand...what should I do in this example?

        import sys
        from PyQt4.QtGui import *
        from PyQt4.QtCore import *
        
        def window():
           app = QApplication(sys.argv)
           w = QWidget()
           b = QPushButton(w)
           b.setText("Hello World!")
           b.move(50,50)
           b.clicked.connect(showdialog)
           w.setWindowTitle("PyQt Dialog demo")
           w.show()
           sys.exit(app.exec_())
        	
        def showdialog():
           d = QDialog()
           b1 = QPushButton("ok",d)
           b1.move(50,50)
           d.setWindowTitle("Dialog")
           d.setWindowModality(Qt.ApplicationModal)
           d.exec_()
        	
        if __name__ == '__main__':
           window()
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Exactly what I said:

          • replace PyQt4 with PyQt5
          • since all the classes are from the widgets module replace QtGui with QtWidgets

          In addition: stop using star imports, it's bad habit and import stuff you do not use.

          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
          1
          • J Offline
            J Offline
            john_hobbyist
            wrote on last edited by john_hobbyist
            #5

            @SGaist

            You are AMAZING!!! Thanx a lot!!!

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

              You're welcome

              Since you have it working now, please mark the thread as solved using the "Topic Tool" button so that other forum users may know a solution has been found.

              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
              1
              • J Offline
                J Offline
                john_hobbyist
                wrote on last edited by
                #7
                This post is deleted!
                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