how can i mark points on top of a Image?
I am trying to mark points on top of a image,
- I select the topleft and bottomright points on the image
- generate grid points on top of the image (something like this )
http://img169.imageshack.us/img169/9...otfigure11.jpg
- the grid should be cleared later
currently i created a ImageItem class derived from QpixmapItem
Code:
#ifndef IMAGEITEM_H
#define IMAGEITEM_H
#include <QGraphicsPixmapItem>
#include <QtDebug>
#include <QGraphicsSceneMouseEvent>
#include <QPoint>
#include <QPainter>
#include <QObject>
{
Q_OBJECT
public:
ImageItem();
public slots:
signals:
};
#endif // IMAGEITEM_H
Code:
#include "imageitem.h"
ImageItem::ImageItem()
{
}
}
emit mouseClicked(event->pos());
}
i can get the topleft and bottomright points from the mousePressEvent
Now my problem is how can i draw points (which can be removed later) on top of QPixmapItem??:confused:
any ideas how to implement this? or if u have a sample code please share :cool:
Re: how can i mark points on top of a Image?
That link looks like a form or dialog with a image. What about a label to display a image and QPainter to draw the points on top ?
Re: how can i mark points on top of a Image?
Quote:
Originally Posted by
montamer
any ideas how to implement this? or if u have a sample code please share :cool:
This is my code to emulate what happen when a user click a mouse button on a desktop and then moves the mouse. A dashed retangle is drawn on desktop to let user see "selection area". All this is done on a screenshoot image. There are
mainly 3 methods:
mousePressEvent =>get mouse coords, start coords
mouseMoveEvent =>get end coords and draw a rectangle on image,
mouseReleaseEvent =>restore original image
I hope you can use my code to do whatever you need.
Bye
Alberto
Code:
.h:
int startx,starty,endx,endy,addable,printed;
QPixmap originalPixmap;
//image where i draw QPixmap copyPixmap;
//temporary image QPixmap savePixmap;
//original image
.cpp:
{
startx=event->globalPos().x()-offsetx+ui->scrollArea->horizontalScrollBar()->value();
starty=event->globalPos().y()-offsety+ui->scrollArea->verticalScrollBar()->value();
addable=1;
}
{
if(addable==1){
if(printed==1){
originalPixmap
=copyPixmap.
copy(QRect());
ui->label->setPixmap(originalPixmap);
}
painter.
setPen(QPen(Qt
::gray,
1, Qt
::DashLine, Qt
::RoundCap, Qt
::RoundJoin));
painter.drawRect(startx,
starty,
event->globalPos().x()-startx-offsetx+ui->scrollArea->horizontalScrollBar()->value(),
event->globalPos().y()-starty-offsety+ui->scrollArea->verticalScrollBar()->value() );
painter.end();
ui->label->setPixmap(originalPixmap);
printed=1;
}
}
{
printed=0;
originalPixmap
=copyPixmap.
copy(QRect());
ui->label->setPixmap(originalPixmap);
if(addable==1){
endx=event->globalPos().x()-offsetx+ui->scrollArea->horizontalScrollBar()->value();
endy=event->globalPos().y()-offsety+ui->scrollArea->verticalScrollBar()->value();
addable=2;
connect(ui
->lineEdit,
SIGNAL(textChanged
(QString)),
this,
SLOT(checkText
(QString)));
}
}