我从QGraphicsView派生了一个类myview,在这个类里我重载了mousepressevent函数。在另一个类mygra里的数据成员里定义一个myview类对象,在类mygra的paintevent函数里的代码如下:
if (pixmap.load(":image/1.bmp"))
{
scene.setSceneRect(0, 0, pixmap.width(), pixmap.height());
view.setScene(&scene);
view.setBackgroundBrush(pixmap);
view.setParent(this);
painter.begin(&pixmap);
color.setRed(255);
painter.setPen(color);
painter.drawPixmap(0, 0, pixmap);
painter.drawEllipse(pixmap.width()/2, pixmap.height()/2, 5, 5);
painter.fillRect(pixmap.width()/2, pixmap.height()/2, 5, 5, color);
painter.end();
view.show();
}
其中scene是一个QGraphicsScene对象,pixmap是一个QPixmap对象,painter是一个QPainter对象,color是一个QColor对象。
为什么程序运行后在图片上没有显示出代码里画的红点?我把painter.begin(&view)也不行。请各位指教。