PDA

View Full Version : PyQt: Scrollbars are not shown with QGraphicsView class being nested under QMainWindo



TheIndependentAquarius
5th April 2018, 06:22
I am supposed to add scrollbars to the screen. The class design shown below is the part of a software that I am supposed to modify and add scrollbars to. The scroll bar code in Window class has been added by me.

It doesn't get shown when I run the program. What am I supposed to correct?




import sys

from PyQt4 import QtGui
from PyQt4 import QtCore

class Window(QtGui.QGraphicsView):

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.ScrollHandDra g)
self.setTransformationAnchor(QtGui.QGraphicsView.A nchorUnderMouse)
self.viewport().setCursor(QtCore.Qt.CrossCursor)
self.setHorizontalScrollBarPolicy(QtCore.Qt.Scroll BarAlwaysOn)
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBa rAlwaysOn)

print "sdsads"


class CityscapesLabelTool(QtGui.QMainWindow):
def __init__(self, parent=None):

QtGui.QMainWindow.__init__(self, parent)
Window()

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