PDA

View Full Version : How do I add a QGraphicsScene to a QGridLayout?



di_zou
10th December 2009, 19:34
I have this:


class MainWidget(QWidget):
def __init__(self):
self.tree = TreeArea(self)
self.display = DisplayArea(self)

gridLayout = QGridLayout()
gridLayout.addWidget(self.tree, 0, 0)
gridLayout.addWidget(self.display, 0, 1)


where TreeArea is:


class TreeArea(QTreeWidget):
def __init__(self, parent):
QTreeWidget.__init__(self, parent)

and DisplayArea is:


class DisplayArea(QGraphicsScene):
def __init__(self, parent):
QGraphicsScene.__init__(self, parent)

Qt doesn't like it when I do gridLayout.addWidget(self.display, 0, 1) since self.display does not inherit QWidget. So how do I add a QGraphicsScene to a layout?

sunil.thaha
11th December 2009, 06:00
you can add only widgets to a layout. Widgets are those you see on the screen. A QGraphicScene is a model class; in other words stores information/data about a scene. You should create a QGraphicsView and add that to the layout.

wagmare
11th December 2009, 06:27
QGraphicScene is for rendering designing area for QGraphicsView() . so instaed of adding QGraphicsScene u first design a QGraphicsView() with the QGraphicsScene and add that graphicsView to your widget mainwindow

di_zou
11th December 2009, 15:00
Thank you, that has worked.