how to mark a point on image.Image is already draw on QLabel and set using setPixmap
Hello
I want to mark a point on image where i click with cursor.
On my widget i use QLabel to disply image.
in that using setPixmap i display image on that QLabel.
no problem is that when image is not available on QLabel and i click mouse i can able to draw point on that label.for draw i implement QPaintEvent()
like
void QWidget::QPaintEvent(QPainteEvent * event)
{
QPainter painter(this);
draw(*painter);
}
here my draw method
void Widget::draw(QPainter *painter)
{
painter.drawpoint();
}
this method draw when image in not in QLable but when i put image on QLabel and then i tray to click on that image it will not draw point on that image.....
should i get the QPainter object of QLabel class
so when image will be present on QLabel and i clicked on it it will mark point on it.
Re: how to mark a point on image.Image is already draw on QLabel and set using setPix
Please provide real code, not an incorrect mockup like you did.
Re: how to mark a point on image.Image is already draw on QLabel and set using setPix
It's true it's a little bit hard to follow what you did and there is many solutions to do what you want :
You can overload the PainEvent of your widget, call the parent method, then draw your point after label is painted. The position may be saved in a proper mouseEvent.
Or inherit QLabel, and in overloaded paintEvent, call the parent method, then draw your point.
Maybe your problem is that your are not calling the parent method in the paintEvent, so result of drawing the point is visible only where there is no image
Re: how to mark a point on image.Image is already draw on QLabel and set using setPix
ok here is my code
this is my widget .cpp file
Widget() //constructor
{
Label1=new QLabel(this);
button=new QPushButton(this);
Point->setx(0):
point->sety(0);
connect(button,SIGNAL(clicked()),this,SLOT(open()) );
}
void Widget::open()
{
Image("E:\\new.tif"); //Image is object of QImage class declare in header file
Label1.setPix(Qt::Pixmap.fromImage(Image)); //that will draw image on QLabel
}
void Widget::QPaintEvent(QPaintEvent *e)
{
QPainter painter(this);
draw(&painter);
}
void Widget::draw(QPainter *painter)
{
Qimage imageicon("E:\\icon.png");
painter.drawImage(point,imageicon);
}
void Widget::mousePressEvent(QMousePressEvent *e)
{
point->setX(e->X()); //getting coordinate of image where i want to draw icon
point->setY(e->Y());
}
if there is something missing in code or some syntax error plz assume right one ...
now u get some idea about my code here my problem is that after clicking on a button it will set image on label then i clicked on that image i want icon at that place where i click but it will not appear on image it is behind the image
so my problem is that instead of QPainter painter(this)
can i write
QPainter painter(Label1);
so i can click on image that will draw icon on image.
which will return me something using that i can draw or mark on image
actually i m working in GIS field so i want to mark some point on image.....like i want to mark some house or some road or some palce.........my image is satellite image.......
Re: how to mark a point on image.Image is already draw on QLabel and set using setPix
Did you try compiling this code? IMO it won't compile.
You need to call the base class implementation in the paint event, that's for sure.
Re: how to mark a point on image.Image is already draw on QLabel and set using setPix
To answer your question, just call the base class in your paintEvent:
Code:
//this will draw your widget, and therefore the label too
//then draw your point
Qpainter painter(this);
painter.drawPoint(x, y);
}
But to answer your problem, if you are trying to implement a GIS engine with QLabeland painting points, maybe you should better read the documentation about about QGraphicsViewand QGraphicsPixmapItem.
Re: how to mark a point on image.Image is already draw on QLabel and set using setPix
@above
tbahks yaar for reply