void resizeEvent(QResizeEvent *e) { if (that) { that->setRect(appRect()); } QGraphicsView::resizeEvent(e); }
void moveEvent(QMoveEvent *e) { if (that) { that->setRect(appRect()); scene->update(); } QGraphicsView::moveEvent(e); }
void ImageWidget::paintEvent(QPaintEvent *) { QRectF desiredRect[4]; desiredRect[0] = QRectF( QPointF(desiredSize.width(), desiredSize.height()), QPointF(2.0*desiredSize.width(), 2.0*desiredSize.height())); desiredRect[1] = QRectF( QPointF(0.0, desiredSize.height()), QPointF(desiredSize.width(), 2.0*desiredSize.height())); desiredRect[2] = QRectF( QPointF(0.0, 0.0), QPointF(desiredSize.width(), desiredSize.height())); desiredRect[3] = QRectF( QPointF(desiredSize.width(), 0.0), QPointF(2.0*desiredSize.width(), desiredSize.height())); QPainter painter; QPen pen(Qt::red, 10, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); QRectF defaultRect(0.0, 0.0, imgSize.width(), imgSize.height()); QRectF appRect(0.0, 0.0, desiredSize.width(), desiredSize.height()); for( int i = 0; i < 4; ++i) { /* load the image */ image.load(fileName[i]); painter.begin(&image); painter.drawPixmap(imagePos(image), QPixmap::fromImage(image)); painter.end(); /* get the area ready to draw in */ painter.begin(this); painter.setCompositionMode(QPainter::CompositionMode_Source); painter.drawImage(desiredRect[i], image, defaultRect); painter.end(); } for (list<QLine>::iterator it = lines.begin(); it != lines.end(); it++) { painter.begin(this); painter.setPen(pen); painter.drawLine(*it); painter.end(); } }