On Thursday 05 February 2015 10:30:04 Alexander Semke wrote: > Am Mittwoch, 4. Februar 2015, 11:22:15 schrieben Sie: > > not sure how the graphicsitem comes into all of this, but no you cant draw > > on it. > > Well, we use QGraphicsScene/View with QGraphicsItems. > > > you can draw on a QGraphicsWidget or you can derive from > > QGraphicsItem and draw in its paint() method. > > The Curve-class is already derived from QGraphicsItem and I reimplement the > paint()-function. As you suggested, I use the QPainter passed to this > function to draw onto a QPixmap. Once I'm done with this I want to call > painter->drawPixmap() to draw on the QGraphicsItem... > Also, by making the painter to paint on the pixmap with > painter.begin(&pixmap) I get the warning "QPainter is already active" - the > painter is already initialized/prepared for the graphics item. > > Any other ideas?
I think you misinterpret (no offense intended) the concept of QGraphicsScene/View and QGraphicsItem. In a short and very simplified way: QGraphicsItem is just a container for the information about what and how to draw (position, brush, pen, etc). QGraphicsScene is manages these items. The actual drawing is done/induced by QGraphicsView. It creates a QPainter and (via QGraphicsScene) calls the paint() function of the items. The painter does not paint onto an item but is initialized to draw on the views drawing area. If you have several view attached to your scene, each view will call the item's paint() function as needed with its own painter. When you call painter.begin(&pixmap) you "misuse" this painter therefore the warning. If you want to manage the painting by internally creating a pixmap you are doing something similar to what happens when you enable caching with QGraphicsItem::setCacheMode(QGraphicsItem::ItemCoordinateCache). I think you should create a separate painter for painting on your internal pixmap and use the supplied painter to paint() to the draw the pixmap (on the view). You might also have a look at http://www.qcustomplot.com. They are doing something similar as you. -- Reinhardt Behm _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest