PDA

View Full Version : Inserting a pushpin on a Image



Vivek1982
28th November 2013, 05:30
Dear All,
Can we insert a image on image something like my first image is GIS MAP (screen shot of google maps after zoomin it to my location). Now there is anyway option or idea to insert a pushpin on the Image at the background. similarly like google map, inserting red pushpin for any location. How to insert pushpin image on map image(screen shot of google map).

Thanks in Advance

Added after 57 minutes:

I have created label where background image is my map, on top of it Im loading new image (pushpin). Now i need set the top image at a known location by default it is coming middle of the left side of my back ground. How to set this top image(pushpin) at my setvalues (50,75).here 50,75 can be my label size.

Vivek1982
28th November 2013, 09:33
hi.. any other class i need use here to move my pushpin to other location. If any, please suggest I will try it.

Vivek1982
28th November 2013, 12:42
I request some one to reply. What should be the approach or idea to create this type of application. means inserting a pushpin on QLabel Image at background sytle sheet.

toufic.dbouk
28th November 2013, 12:57
What is the reason behind putting a pushpin on a QLable ?
When do you want to do that ?
BTW you cant request anyone to reply. Instead you can nicely ask for someone to help.

Good Luck.

Vivek1982
28th November 2013, 13:40
okay..I need to give the proper info why Im inserting pushpin. I have created a application which works on Network via server client architecture. I have done that portion. Now I have background Image on a Qlabel as our map image. when they come on to the network with certain protocol.In QLabel pushpin can be inserted.this is wat Im doing, how many people are there in the network by seeing the Label.thats all. Now I need a help to do this..

Thanks

ChrisW67
29th November 2013, 04:19
Have you considered using QGraphicsView with the map and markers as objects in the QGraphicsScene, or using a Javascript solution in a QWebView?

Vivek1982
29th November 2013, 04:47
thanks for the reply.. I'm newbie for Qt. So, initially I would like go in simple way may be coding looks difficult. Okay I will have a look on QGraphics view. Any suggestion on my present application. Basically my query was loading an image on QLabel, where in Qlabel background is also a image. But default If i'm inserting image by Qpixmap. Its coming on default position of Qlabel. whether that image can be set according to our co-ordinates on QLabel.

This is my idea, If it works good or as u suggested another way I will look into it.

ChrisW67
29th November 2013, 08:01
If you want to persist with the QLabel then:

Your label should have a fixed size matching the map, X by Y pixels
Set the background image for the label to your "map".
When you need to draw a marker:
Determine what pixel in (X by Y) corresponds to the position you want to mark
Create a QPixmap at X by Y pixels
Create a QPainter on the QPixmap
QPainter::fillRect() with Qt::Transparent paint
QPainter::drawPixmap() with the computed coordinates and your marker pixmap
End the painter
Set the new pixmap on the label


You could draw the map and marker pixmaps into the same pixmap and set that in the label. This code is not much different from the code you would put in a QWidget::paintEvent() to make a self-contained "map" widget.

Vivek1982
29th November 2013, 13:11
Thanks for giving me suggestion. I have written code, still some minor problem may be there in coding. I have created slot with QTimer like after 15 sec this slot should be executed. I have QLabel in UI form which is matching with the size of my map image. This same map image is loaded as background image of my Qlabel.coming to the private slot.


void MainWindow::on_timeout()
{
lbl=ui->label;// QLabel declaration
pixcell= new QPixmap(500,500);//determine the pixcell where to mark
//setting back ground image(map) is done in Ui form.
QPixmap pixcell(":/pin30_red.png");
pait=new QPainter;
//pait->begin(pixcell);
pait->fillRect(pixcell.rect(),Qt::transparent);
pait->drawImage(500,500,lbl);
pait->end();
lbl->setPixmap(pixcell);
lbl->show();
}

I'm getting errors C:/Users/398292/Desktop/Qt05092013/maptool/mainwindow.cpp:43: error: no matching function for call to 'QPainter::drawImage(int, int, QLabel*&)'.Any problem in the coding or declaration made in the SLOT?

Thanks.

ChrisW67
30th November 2013, 09:10
The error messages tells you exactly what the coding error is. However, you need to read my instructions again because have missed the point. You are drawing a pixmap to then put on the label. The label is not involved in the drawing process at all.

Vivek1982
30th November 2013, 10:06
Okay first I will call my pixcell on the label by default it will come at aligned left vertical middle....then I will repeat same process let me check...thanks

Vivek1982
2nd December 2013, 05:22
pait=new QPainter;
pixcell = new QPixmap();
QPixmap pixcell(":/pin30_red.png");

lbl->setPixmap(pixcell);

//pait->begin(pixcell);
pait->fillRect(pixcell.rect(),Qt::transparent);
pait->drawPixmap(50,50,pixcell);
pait->end();
lbl->setPixmap(pixcell);
lbl->show();



Initially, I have set the label with the Pixcell. Still I'm not getting it. Please I need to go where I'm going wrong. I have loaded back ground Image on top of it Im calling for this Pixcell image. I have given the X,Y points also.I'm checking all the line codes etc/logics no success, I need a help.
Thanks

Vivek1982
2nd December 2013, 07:48
QPixmap pixcell(":/pin30_red.png");
lbl->pixcell=new QPixmap(250,250);

//lbl->setPixmap(pixcell);
pait=new QPainter(&pixcell);
//pait->begin(pixcell);
pait->fillRect(pixcell.rect(),Qt::transparent);
pait->drawPixmap(250,250,&pixcell);
pait->end();
//lbl->setPixmap(pixcell);
//pixcell.fill(lbl,250,250);
lbl->setPixmap(pixcell);



still no result.How to place pixmap on the desired co-ordinates of Qlabel

Vivek1982
2nd December 2013, 10:32
Dear all, I'm sorry. I'm posting many codes, what all the seems to be working a bit also as for my requirement Im posting. Finally I got it. Im not able to move the image. Im able to create a copy of it


QPixmap pixcell(":/pin30_red.png");

QPainter pait(&pixcell);
pait.fillRect(pixcell.rect(),Qt::transparent);
pait.drawPixmap(75,75,100,100,pixcell);
pait.end();
lbl->setPixmap(pixcell);


when I execute this no change pushpin is coming at default left bottom of Label.
If the same is executed by pait.drawPixmap(0,0,20,20,pixcell) a small pushpin is created in the label superimposing that old pushpin.but it is very small but still im not able to move it far bcoz my label size is 749*456.plz suggest me or help how to resolve this.

Vivek1982
2nd December 2013, 15:36
Dear ChrisW67,
I checked fully regarding code and your suggestions..but still no result...actually in my ui form alignment is set for left vertical centre whether this is a problem I'm not sure...please I need a help I'm stuck up...I'm trying all the logics though its wrong or right but no result..

ChrisW67
3rd December 2013, 00:16
A complete simple example showing one way to do it (slightly different to my explanation above):


#include <QApplication>
#include <QWidget>
#include <QPainter>
#include <QPixmap>
#include <QDebug>

class Widget: public QWidget {
Q_OBJECT
public:
Widget(QWidget *p = 0): QWidget(p) {
setFixedSize(QSize(512, 512));
background.load("background_512x512.png");
marker.load("marker_16x16.png");
}

void setMarkedPoint(const QPoint &point) {
markedPoint = point;
update();
}
protected:
void paintEvent(QPaintEvent *event) {
QPainter p(this);
p.drawPixmap(0, 0, background);
if (!markedPoint.isNull())
p.drawPixmap(markedPoint, marker);
}

private:
QPixmap background;
QPixmap marker;
QPoint markedPoint;
};

int main(int argc, char *argv[]) {
QApplication app(argc, argv);

Widget w;
w.show();
w.setMarkedPoint(QPoint(100, 100));
return app.exec();
}
#include "main.moc"

You need to provide the two images.

Vivek1982
3rd December 2013, 07:58
Thanks for code chrisW67, I will work on it.I hope this will fit into my application also.

Added after 53 minutes:

Dear All,

I have attached the complete project in zip files. I have used MainWindow(object name).I tried with chrisw example.but still I dint get my error or my mistake where im going wrong.here in code atlast image to be converted to pixmap conversion as to be done. Still if doesn't work or if my code is wrong let me know. I will try in other way Qgraphics/QWidget.
thanks in advance for your help/suggestion