[Qt-interest] question regarding polygon and imagviewer

Mahendra G.R mahendra at mahendragr.com
Fri Oct 29 12:12:46 CEST 2010


Hello all,

i'm using the image viewer example to load an image, now, i have to draw a
rectangle/polygon inside that image. Like, when i make a mouseclick on the
image, a point should be drawn after each click and these points should be
connected (and get a triangle when there are 3 points).  i'm using
mousePressEvent to get the co ordinates, store them, then use these co
ordinages in Qpainters paintEvent function.  But i dont see any
lines/polygons.  Here is my code :

*void ImageViewer::mousePressEvent(QMouseEvent *e)
{
   if (e->buttons() != Qt::LeftButton)
    return;
    mousePosX = (double) e->pos().x();
    mousePosY = (double) e->pos().y();

    QTextStream out(stdout);
    out <<mousePosX<<" "<<mousePosY<<endl;

}

void ImageViewer::paintEvent(QPaintEvent *)
{*
*    QPointF mouseCord[10] = {QPointF(mousePosX,mousePosY)};
    QPainter painter(this);
    painter.setBackgroundMode(Qt::OpaqueMode);
    painter.setPen(QColor(255, 0, 0, 255));
    QTextStream out(stdout);
    out <<"Displaying in paintevent"<<mousePosX<<" "<<mousePosY<<endl;
    painter.drawPolygon(mouseCord, 3);


}*

can any one shed some light on this.


Thanks,
Regards

-- 
http://www.mahendragr.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101029/9a93ddd4/attachment.html 


More information about the Qt-interest-old mailing list