Search code examples
pythonqt4

from PyQt4.QtGui: NameError: name 'QtGui' is not defined


I have followed the specific kind of import rather than writing *.
from PyQt4.QtGui

What else am I missing?

import sys

from PyQt4.QtGui import QMainWindow, QSizePolicy, QWidget, QVBoxLayout, QAction,\
        QKeySequence, QLabel, QItemSelectionModel, QMessageBox, QFileDialog, QFrame, \
        QDockWidget, QProgressBar, QProgressDialog

from PyQt4.QtCore import SIGNAL, QSettings, QSize, QPoint, QVariant, QFileInfo, QTimer, pyqtSignal, QObject


class Window(QtGui.QMainWindow):

    def __init__(self, parent=None):
        QtGui.QGraphicsView.__init__(self, parent)
        self.scene = QtGui.QGraphicsScene(self)
        self.scene.setBackgroundBrush(QtGui.QBrush(QtCore.Qt.darkGray, QtCore.Qt.SolidPattern))
        self.setScene(self.scene)

        self.setDragMode(QtGui.QGraphicsView.ScrollHandDrag)
        self.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
        self.viewport().setCursor(QtCore.Qt.CrossCursor)
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

        self._pan = False
        self._draw = False
        self._moved = False
        self._sel = False
        self.pen = None
        self.penid = None
        self.cmap = None
        self.penwidth = 4
        self._redoStack = []
        self._histStates = []
        self._baseRects = [] 

app = QtGui.QApplication(sys.argv)
GUI = Window()
sys.exit(app.exec_())

Solution

  • I added the following lines to the code and that solved the error:

    from PyQt4 import QtGui
    from PyQt4 import QtCore
    

    It looks like this now:

    import sys
    
    from PyQt4 import QtGui
    from PyQt4 import QtCore
    
    from PyQt4.QtGui import QMainWindow, QSizePolicy, QWidget, QVBoxLayout, QAction,\
            QKeySequence, QLabel, QItemSelectionModel, QMessageBox, QFileDialog, QFrame, \
            QDockWidget, QProgressBar, QProgressDialog
    
    from PyQt4.QtCore import SIGNAL, QSettings, QSize, QPoint, QVariant, QFileInfo, QTimer, pyqtSignal, QObject