Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. PyQT4 App
Forum Updated to NodeBB v4.3 + New Features

PyQT4 App

Scheduled Pinned Locked Moved Unsolved Qt for Python
42 Posts 4 Posters 10.0k 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.
  • M Mitko

    @JonB

    I try to upgrade from PyQT4 to 5, but now i have other types of errors, that i don't understand.
    Can someone help me ?
    254295116_440010580821929_772944740554573543_n.jpg

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

    @Mitko
    I don't think this is actually anything to do with PyQt, or Qt. If you had copied and pasted the text instead of screenshot I could have quoted from it. But I see a Python3.8 json library loader complaining about some character in its JSON input.

    M 1 Reply Last reply
    0
    • JonBJ JonB

      @Mitko
      I don't think this is actually anything to do with PyQt, or Qt. If you had copied and pasted the text instead of screenshot I could have quoted from it. But I see a Python3.8 json library loader complaining about some character in its JSON input.

      M Offline
      M Offline
      Mitko
      wrote on last edited by
      #9

      @JonB

      The error was, because part one of the files (the json), containing the xbee commands, has Russian in it, so the problem was with UTF-8 encoding, but i fix it.
      But now i have the following problem:

      File "C:/xbee-gui-master/MainForm.py", line 18, in <module>
          class Block(QtGui.QMainWindow, QtGui.QTreeView):
      NameError: name 'QtGui' is not defined
      

      How to solve it ?

      JonBJ 1 Reply Last reply
      0
      • M Mitko

        @JonB

        The error was, because part one of the files (the json), containing the xbee commands, has Russian in it, so the problem was with UTF-8 encoding, but i fix it.
        But now i have the following problem:

        File "C:/xbee-gui-master/MainForm.py", line 18, in <module>
            class Block(QtGui.QMainWindow, QtGui.QTreeView):
        NameError: name 'QtGui' is not defined
        

        How to solve it ?

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

        @Mitko
        Qt5 moved widget code from QtGui to QtWidgets, change to that. You will have to do the same for any other widget stuff. I gave you reference to https://wiki.qt.io/Transition_from_Qt_4.x_to_Qt5 for this --- it's the very first item there --- and told you that's what I used to do the porting work.

        M 1 Reply Last reply
        1
        • JonBJ JonB

          @Mitko
          Qt5 moved widget code from QtGui to QtWidgets, change to that. You will have to do the same for any other widget stuff. I gave you reference to https://wiki.qt.io/Transition_from_Qt_4.x_to_Qt5 for this --- it's the very first item there --- and told you that's what I used to do the porting work.

          M Offline
          M Offline
          Mitko
          wrote on last edited by
          #11

          @JonB
          I began to solve this problem, but now i have this error:

           C:\xbee-gui-master\PyQT\Scripts\python.exe C:/xbee-gui-master/MainForm.py
          Traceback (most recent call last):
            File "C:/xbee-gui-master/MainForm.py", line 360, in <module>
              main()
            File "C:/xbee-gui-master/MainForm.py", line 355, in main
              bl = Block()
            File "C:/xbee-gui-master/MainForm.py", line 26, in __init__
              self.setWindowIcon(QtWidgets.QIcon("zigbee.png"))
          AttributeError: module 'PyQt5.QtWidgets' has no attribute 'QIcon'
          
          jsulmJ 1 Reply Last reply
          0
          • M Mitko

            @JonB
            I began to solve this problem, but now i have this error:

             C:\xbee-gui-master\PyQT\Scripts\python.exe C:/xbee-gui-master/MainForm.py
            Traceback (most recent call last):
              File "C:/xbee-gui-master/MainForm.py", line 360, in <module>
                main()
              File "C:/xbee-gui-master/MainForm.py", line 355, in main
                bl = Block()
              File "C:/xbee-gui-master/MainForm.py", line 26, in __init__
                self.setWindowIcon(QtWidgets.QIcon("zigbee.png"))
            AttributeError: module 'PyQt5.QtWidgets' has no attribute 'QIcon'
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #12

            @Mitko said in PyQT4 App:

            QIcon

            This one is in gui module.
            I guess in PyQt it is PyQt5.QtGui

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            M 1 Reply Last reply
            0
            • jsulmJ jsulm

              @Mitko said in PyQT4 App:

              QIcon

              This one is in gui module.
              I guess in PyQt it is PyQt5.QtGui

              M Offline
              M Offline
              Mitko
              wrote on last edited by
              #13

              @jsulm

              I change it, but now i have this:

               C:\xbee-gui-master\PyQT\Scripts\python.exe C:/xbee-gui-master/MainForm.py
              Traceback (most recent call last):
                File "C:/xbee-gui-master/MainForm.py", line 360, in <module>
                  main()
                File "C:/xbee-gui-master/MainForm.py", line 355, in main
                  bl = Block()
                File "C:/xbee-gui-master/MainForm.py", line 26, in __init__
                  self.setWindowIcon(QtWidgets.QGui("zigbee.png"))
              AttributeError: module 'PyQt5.QtWidgets' has no attribute 'QGui'
              
              jsulmJ 1 Reply Last reply
              0
              • M Mitko

                @jsulm

                I change it, but now i have this:

                 C:\xbee-gui-master\PyQT\Scripts\python.exe C:/xbee-gui-master/MainForm.py
                Traceback (most recent call last):
                  File "C:/xbee-gui-master/MainForm.py", line 360, in <module>
                    main()
                  File "C:/xbee-gui-master/MainForm.py", line 355, in main
                    bl = Block()
                  File "C:/xbee-gui-master/MainForm.py", line 26, in __init__
                    self.setWindowIcon(QtWidgets.QGui("zigbee.png"))
                AttributeError: module 'PyQt5.QtWidgets' has no attribute 'QGui'
                
                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #14

                @Mitko said in PyQT4 App:

                PyQt5.QtWidgets' has no attribute 'QGui'

                I did not suggest to write QtWidgets.QGui but PyQt5.QtGui

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                M 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Mitko said in PyQT4 App:

                  PyQt5.QtWidgets' has no attribute 'QGui'

                  I did not suggest to write QtWidgets.QGui but PyQt5.QtGui

                  M Offline
                  M Offline
                  Mitko
                  wrote on last edited by
                  #15

                  @jsulm

                   C:\xbee-gui-master\PyQT\Scripts\python.exe C:/xbee-gui-master/MainForm.py
                  Traceback (most recent call last):
                    File "C:/xbee-gui-master/MainForm.py", line 360, in <module>
                      main()
                    File "C:/xbee-gui-master/MainForm.py", line 355, in main
                      bl = Block()
                    File "C:/xbee-gui-master/MainForm.py", line 26, in __init__
                      self.setWindowIcon(PyQt5.QGui("zigbee.png"))
                  NameError: name 'PyQt5' is not defined 
                  
                  jsulmJ 1 Reply Last reply
                  0
                  • M Mitko

                    @jsulm

                     C:\xbee-gui-master\PyQT\Scripts\python.exe C:/xbee-gui-master/MainForm.py
                    Traceback (most recent call last):
                      File "C:/xbee-gui-master/MainForm.py", line 360, in <module>
                        main()
                      File "C:/xbee-gui-master/MainForm.py", line 355, in main
                        bl = Block()
                      File "C:/xbee-gui-master/MainForm.py", line 26, in __init__
                        self.setWindowIcon(PyQt5.QGui("zigbee.png"))
                    NameError: name 'PyQt5' is not defined 
                    
                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #16

                    @Mitko said in PyQT4 App:

                    PyQt5.QGui("zigbee.png")

                    What is this?! You want to use QIcon, right?
                    It should be I guess

                    QtGui.QIcon("zigbee.png")
                    

                    It is also shown in the documentation which you should consult: https://doc.qt.io/qtforpython-5/PySide2/QtGui/QIcon.html

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    M 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @Mitko said in PyQT4 App:

                      PyQt5.QGui("zigbee.png")

                      What is this?! You want to use QIcon, right?
                      It should be I guess

                      QtGui.QIcon("zigbee.png")
                      

                      It is also shown in the documentation which you should consult: https://doc.qt.io/qtforpython-5/PySide2/QtGui/QIcon.html

                      M Offline
                      M Offline
                      Mitko
                      wrote on last edited by
                      #17

                      @jsulm

                       C:\xbee-gui-master\PyQT\Scripts\python.exe C:/xbee-gui-master/MainForm.py
                      Traceback (most recent call last):
                        File "C:/xbee-gui-master/MainForm.py", line 360, in <module>
                          main()
                        File "C:/xbee-gui-master/MainForm.py", line 355, in main
                          bl = Block()
                        File "C:/xbee-gui-master/MainForm.py", line 26, in __init__
                          self.setWindowIcon(QtGui.QIcon("zigbee.png"))
                      NameError: name 'QtGui' is not defined 
                      
                      jsulmJ 1 Reply Last reply
                      0
                      • M Mitko

                        @jsulm

                         C:\xbee-gui-master\PyQT\Scripts\python.exe C:/xbee-gui-master/MainForm.py
                        Traceback (most recent call last):
                          File "C:/xbee-gui-master/MainForm.py", line 360, in <module>
                            main()
                          File "C:/xbee-gui-master/MainForm.py", line 355, in main
                            bl = Block()
                          File "C:/xbee-gui-master/MainForm.py", line 26, in __init__
                            self.setWindowIcon(QtGui.QIcon("zigbee.png"))
                        NameError: name 'QtGui' is not defined 
                        
                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #18

                        @Mitko said in PyQT4 App:

                        name 'QtGui' is not defined

                        You of course have to import this module like any other module

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        M 1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @Mitko said in PyQT4 App:

                          name 'QtGui' is not defined

                          You of course have to import this module like any other module

                          M Offline
                          M Offline
                          Mitko
                          wrote on last edited by
                          #19

                          @jsulm
                          Via Interpreter ? I've try, it seems to installed, but i've got same error

                          jsulmJ 1 Reply Last reply
                          0
                          • M Mitko

                            @jsulm
                            Via Interpreter ? I've try, it seems to installed, but i've got same error

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #20

                            @Mitko said in PyQT4 App:

                            Via Interpreter ?

                            Don't know what you mean.

                            from PyQt5 import QtGui
                            

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            M 1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @Mitko said in PyQT4 App:

                              Via Interpreter ?

                              Don't know what you mean.

                              from PyQt5 import QtGui
                              
                              M Offline
                              M Offline
                              Mitko
                              wrote on last edited by
                              #21

                              @jsulm
                              Thank you, i fix this

                              But now i have this:

                               Traceback (most recent call last):
                                File "C:/xbee-gui-master/MainForm.py", line 360, in <module>
                                  main()
                                File "C:/xbee-gui-master/MainForm.py", line 355, in main
                                  bl = Block()
                                File "C:/xbee-gui-master/MainForm.py", line 28, in __init__
                                  self.centralWidgetLayout = QtGui.QVBoxLayout(self.centralWidget)
                              AttributeError: module 'PyQt5.QtGui' has no attribute 'QVBoxLayout'
                              
                              
                              jsulmJ 1 Reply Last reply
                              0
                              • M Mitko

                                @jsulm
                                Thank you, i fix this

                                But now i have this:

                                 Traceback (most recent call last):
                                  File "C:/xbee-gui-master/MainForm.py", line 360, in <module>
                                    main()
                                  File "C:/xbee-gui-master/MainForm.py", line 355, in main
                                    bl = Block()
                                  File "C:/xbee-gui-master/MainForm.py", line 28, in __init__
                                    self.centralWidgetLayout = QtGui.QVBoxLayout(self.centralWidget)
                                AttributeError: module 'PyQt5.QtGui' has no attribute 'QVBoxLayout'
                                
                                
                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #22

                                @Mitko said in PyQT4 App:

                                QVBoxLayout

                                Please do also some research on your own!
                                If you google for QVBoxLayout you will find https://doc.qt.io/qt-5/qvboxlayout.html and there it is clearly stated that it is in widgets module (qmake: QT += widgets).

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                M 2 Replies Last reply
                                1
                                • jsulmJ jsulm

                                  @Mitko said in PyQT4 App:

                                  QVBoxLayout

                                  Please do also some research on your own!
                                  If you google for QVBoxLayout you will find https://doc.qt.io/qt-5/qvboxlayout.html and there it is clearly stated that it is in widgets module (qmake: QT += widgets).

                                  M Offline
                                  M Offline
                                  Mitko
                                  wrote on last edited by
                                  #23

                                  @jsulm
                                  I'm new and don't understand everything

                                  1 Reply Last reply
                                  0
                                  • jsulmJ jsulm

                                    @Mitko said in PyQT4 App:

                                    QVBoxLayout

                                    Please do also some research on your own!
                                    If you google for QVBoxLayout you will find https://doc.qt.io/qt-5/qvboxlayout.html and there it is clearly stated that it is in widgets module (qmake: QT += widgets).

                                    M Offline
                                    M Offline
                                    Mitko
                                    wrote on last edited by
                                    #24

                                    @jsulm

                                    I've try this but i have same error

                                    from PyQt5.QtWidgets import (QApplication, QWidget, QVBoxLayout, QHBoxLayout,
                                                                 QPushButton, QLabel, QLineEdit, QTabBar,
                                                                 QFrame, QStackedLayout)
                                    
                                    JonBJ 1 Reply Last reply
                                    0
                                    • M Mitko

                                      @jsulm

                                      I've try this but i have same error

                                      from PyQt5.QtWidgets import (QApplication, QWidget, QVBoxLayout, QHBoxLayout,
                                                                   QPushButton, QLabel, QLineEdit, QTabBar,
                                                                   QFrame, QStackedLayout)
                                      
                                      JonBJ Offline
                                      JonBJ Offline
                                      JonB
                                      wrote on last edited by
                                      #25

                                      @Mitko
                                      You should only get the same error if you left the code with QtGui.QVBoxLayout(self.centralWidget). After the import it should work with plain QVBoxLayout(self.centralWidget). Otherwise please don't say " same error" when so many errors are flying around, please show the actual line of any error and paste the error message.

                                      M 1 Reply Last reply
                                      1
                                      • JonBJ JonB

                                        @Mitko
                                        You should only get the same error if you left the code with QtGui.QVBoxLayout(self.centralWidget). After the import it should work with plain QVBoxLayout(self.centralWidget). Otherwise please don't say " same error" when so many errors are flying around, please show the actual line of any error and paste the error message.

                                        M Offline
                                        M Offline
                                        Mitko
                                        wrote on last edited by
                                        #26

                                        @JonB

                                        When i use:

                                        from PyQt5 import QtWidgets, QtCore, QtGui, QVBoxLayout
                                        

                                        I have this:

                                        File "C:/xbee-gui-master/MainForm.py", line 3, in <module>
                                         from PyQt5 import QtWidgets, QtCore, QtGui, QVBoxLayout
                                        ImportError: cannot import name 'QVBoxLayout' from 'PyQt5' (C:\xbee-gui-master\PyQT\lib\site-packages\PyQt5\__init__.py)
                                        

                                        When i use:

                                        from PyQt5 import QtWidgets, QtCore, QtGui
                                        
                                        from PyQt5.QtWidgets import (QApplication, QWidget, QVBoxLayout, QHBoxLayout,
                                                                     QPushButton, QLabel, QLineEdit, QTabBar,
                                                                     QFrame, QStackedLayout)
                                        

                                        I have this:

                                        File "C:/xbee-gui-master/MainForm.py", line 35, in __init__
                                           self.centralWidgetLayout = QtGui.QVBoxLayout(self.centralWidget)
                                        AttributeError: module 'PyQt5.QtGui' has no attribute 'QVBoxLayout'
                                        
                                        JonBJ 1 Reply Last reply
                                        0
                                        • M Mitko

                                          @JonB

                                          When i use:

                                          from PyQt5 import QtWidgets, QtCore, QtGui, QVBoxLayout
                                          

                                          I have this:

                                          File "C:/xbee-gui-master/MainForm.py", line 3, in <module>
                                           from PyQt5 import QtWidgets, QtCore, QtGui, QVBoxLayout
                                          ImportError: cannot import name 'QVBoxLayout' from 'PyQt5' (C:\xbee-gui-master\PyQT\lib\site-packages\PyQt5\__init__.py)
                                          

                                          When i use:

                                          from PyQt5 import QtWidgets, QtCore, QtGui
                                          
                                          from PyQt5.QtWidgets import (QApplication, QWidget, QVBoxLayout, QHBoxLayout,
                                                                       QPushButton, QLabel, QLineEdit, QTabBar,
                                                                       QFrame, QStackedLayout)
                                          

                                          I have this:

                                          File "C:/xbee-gui-master/MainForm.py", line 35, in __init__
                                             self.centralWidgetLayout = QtGui.QVBoxLayout(self.centralWidget)
                                          AttributeError: module 'PyQt5.QtGui' has no attribute 'QVBoxLayout'
                                          
                                          JonBJ Offline
                                          JonBJ Offline
                                          JonB
                                          wrote on last edited by JonB
                                          #27

                                          @Mitko
                                          The first error is correct. from PyQt5 import QtWidgets, QtCore, QtGui is good. QVBoxLayout is not in PyQt5, so the error is correct.

                                          Your second example is correct. QtWidgets does contain QVBoxLayout so that is good.

                                          Given which, it is hardly surprising that

                                          self.centralWidgetLayout = QtGui.QVBoxLayout(self.centralWidget)
                                          

                                          gives the error it does, is it? You know that QVBoxLayout has been moved from QtGui in Qt 4 to QtWidgets in Qt 5, don't you, because that is what you are supposed to be changing to make it work. So there's no point putting what used to work and does not work now.

                                          Given your second example code, there are two ways you can address QVBoxLayout:

                                          • QtWidgets.QVBoxLayout: This is allowed from your from PyQt5 import QtWidgets line.

                                          • QVBoxLayout: This is allowed from your from PyQt5.QtWidgets import (QApplication, QWidget, QVBoxLayout, ... line.

                                          M 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 Extensions
                                          • Unsolved