I need to design and develop a kind of graphics piece of software, which can edit customized files containing graphical elements, etc.
I expect the piece of software to contain many documents thanks to the QMdiArea
which is actually my central widget inside of my QMainWindow
.
For each document, I will need both a QGraphicsView
and a QGraphicsScene
as well, since they work together.
Now, my question is, should I inherit QGraphicsView
with a protected/private member to its own QGraphicsScene
, or should I create a class which inherits QWidget
and handles instances of QGraphicsView
/ QGraphicsScene
?
Or is there any solution left that I didn't think about?
First off, I don't think you need a QWidget to manage the QGraphicsScene and QGraphicsView. With that in mind, the "best practice" is typically to avoid subclassing if possible. Eventually you might have to subclass QGraphicsView (if you want to change its default functionality), but nothing in your question implies that you need to right now. Also note that there is a function
QGraphicsView::scene()
that returns the view's current scene, so there is no need to make the scene a member (it already is).If you ever need to access a particular view or scene, you can do something like this:
See also
QMdiArea::subWindowList()
which returns a list of all the sub windows.