I'm trying to make a function similar to impoly (from matlab) in Qt. Right now, I have a subclass of QGraphicsView and have set the virtual function "drawBackground" as:
void roiwindow::drawBackground(QPainter *painter, const QRectF &rect)
{
painter->save();
painter->drawImage(rect, *refimage);
painter->restore();
}
This works great and is basically exactly what I want as far as the background layer. Now, I'm trying to add circles that will eventually act as nodes for the polygon. I did this by using:
QGraphicsView *view = new QGraphicsView(this);
view->show();
QGraphicsEllipseItem *e1;
e1 = this->addEllipse(20, 20, 30, 30, QColor(0, 0, 0), Qt::white);
e1->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsMovable);
This is sort of what I want. But, there is a problem that when I click and drag the ellipses, the background of the ellipse is a scaled down version of *refimage... This leaves sort of a streak across the screen but it disappears when I click on another window or minimize the window. Does QGraphicsItem also call drawBackground? If so it seems to only call it when the item is being dragged. Any suggestions for how I can code this better? Thanks.