PyQT4 App
-
@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.8json
library loader complaining about some character in its JSON input.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 ?
-
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 ?
@Mitko
Qt5 moved widget code fromQtGui
toQtWidgets
, 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. -
@Mitko
Qt5 moved widget code fromQtGui
toQtWidgets
, 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.@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'
-
@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'
-
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'
-
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'
-
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
-
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
PyQt5.QGui("zigbee.png")
What is this?! You want to use QIcon, right?
It should be I guessQtGui.QIcon("zigbee.png")
It is also shown in the documentation which you should consult: https://doc.qt.io/qtforpython-5/PySide2/QtGui/QIcon.html
-
PyQt5.QGui("zigbee.png")
What is this?! You want to use QIcon, right?
It should be I guessQtGui.QIcon("zigbee.png")
It is also shown in the documentation which you should consult: https://doc.qt.io/qtforpython-5/PySide2/QtGui/QIcon.html
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
-
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
-
-
@jsulm
Thank you, i fix thisBut 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'
-
@jsulm
Thank you, i fix thisBut 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'
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). -
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). -
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). -
I've try this but i have same error
from PyQt5.QtWidgets import (QApplication, QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel, QLineEdit, QTabBar, QFrame, QStackedLayout)
@Mitko
You should only get the same error if you left the code withQtGui.QVBoxLayout(self.centralWidget)
. After theimport
it should work with plainQVBoxLayout(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. -
@Mitko
You should only get the same error if you left the code withQtGui.QVBoxLayout(self.centralWidget)
. After theimport
it should work with plainQVBoxLayout(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.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'
-
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'
@Mitko
The first error is correct.from PyQt5 import QtWidgets, QtCore, QtGui
is good.QVBoxLayout
is not inPyQt5
, so the error is correct.Your second example is correct.
QtWidgets
does containQVBoxLayout
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 fromQtGui
in Qt 4 toQtWidgets
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 yourfrom PyQt5 import QtWidgets
line. -
QVBoxLayout
: This is allowed from yourfrom PyQt5.QtWidgets import (QApplication, QWidget, QVBoxLayout, ...
line.
-
-
@Mitko
The first error is correct.from PyQt5 import QtWidgets, QtCore, QtGui
is good.QVBoxLayout
is not inPyQt5
, so the error is correct.Your second example is correct.
QtWidgets
does containQVBoxLayout
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 fromQtGui
in Qt 4 toQtWidgets
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 yourfrom PyQt5 import QtWidgets
line. -
QVBoxLayout
: This is allowed from yourfrom PyQt5.QtWidgets import (QApplication, QWidget, QVBoxLayout, ...
line.
Hi, i'm really grateful for your help so far.
I managed to clear that types of errors.
But now i have different types of 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 367, in <module> main() File "C:/xbee-gui-master/MainForm.py", line 362, in main bl = Block() File "C:/xbee-gui-master/MainForm.py", line 50, in __init__ self.all_tab() File "C:/xbee-gui-master/MainForm.py", line 63, in all_tab self.tab_control() File "C:/xbee-gui-master/MainForm.py", line 160, in tab_control self.list_all_commands() File "C:/xbee-gui-master/MainForm.py", line 211, in list_all_commands self.connect(self.view, QtCore.SIGNAL("clicked(const QModelIndex&)"), on_item_clicked) AttributeError: 'Block' object has no attribute 'connect'
Can you please help me ?
-