Results 1 to 17 of 17

Thread: Inserting a pushpin on a Image

  1. #1
    Join Date
    Sep 2013
    Posts
    107
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default Re: Inserting a pushpin on a Image

    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.
    Last edited by Vivek1982; 28th November 2013 at 04:30.

  2. #2
    Join Date
    Sep 2013
    Posts
    107
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default Re: Inserting a pushpin on a Image

    hi.. any other class i need use here to move my pushpin to other location. If any, please suggest I will try it.

  3. The following 2 users say thank you to Vivek1982 for this useful post:


  4. #3
    Join Date
    Sep 2013
    Posts
    107
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default Re: Inserting a pushpin on a Image

    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.

  5. #4
    Join Date
    Dec 2012
    Posts
    197
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    25
    Thanked 41 Times in 33 Posts

    Default Re: Inserting a pushpin on a Image

    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.
    Last edited by toufic.dbouk; 28th November 2013 at 12:07.

  6. The following user says thank you to toufic.dbouk for this useful post:


  7. #5
    Join Date
    Sep 2013
    Posts
    107
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default Re: Inserting a pushpin on a Image

    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

  8. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Inserting a pushpin on a Image

    Have you considered using QGraphicsView with the map and markers as objects in the QGraphicsScene, or using a Javascript solution in a QWebView?

  9. #7
    Join Date
    Sep 2013
    Posts
    107
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default Re: Inserting a pushpin on a Image

    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.

  10. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Inserting a pushpin on a Image

    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.

  11. #9
    Join Date
    Sep 2013
    Posts
    107
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default Re: Inserting a pushpin on a Image

    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.
    Qt Code:
    1. void MainWindow::on_timeout()
    2. {
    3. lbl=ui->label;// QLabel declaration
    4. pixcell= new QPixmap(500,500);//determine the pixcell where to mark
    5. //setting back ground image(map) is done in Ui form.
    6. QPixmap pixcell(":/pin30_red.png");
    7. pait=new QPainter;
    8. //pait->begin(pixcell);
    9. pait->fillRect(pixcell.rect(),Qt::transparent);
    10. pait->drawImage(500,500,lbl);
    11. pait->end();
    12. lbl->setPixmap(pixcell);
    13. lbl->show();
    14. }
    To copy to clipboard, switch view to plain text mode 

    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.

  12. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Inserting a pushpin on a Image

    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.

  13. #11
    Join Date
    Sep 2013
    Posts
    107
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default Re: Inserting a pushpin on a Image

    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

  14. #12
    Join Date
    Sep 2013
    Posts
    107
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default Re: Inserting a pushpin on a Image

    Qt Code:
    1. pait=new QPainter;
    2. pixcell = new QPixmap();
    3. QPixmap pixcell(":/pin30_red.png");
    4.  
    5. lbl->setPixmap(pixcell);
    6.  
    7. //pait->begin(pixcell);
    8. pait->fillRect(pixcell.rect(),Qt::transparent);
    9. pait->drawPixmap(50,50,pixcell);
    10. pait->end();
    11. lbl->setPixmap(pixcell);
    12. lbl->show();
    To copy to clipboard, switch view to plain text mode 


    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

  15. #13
    Join Date
    Sep 2013
    Posts
    107
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default Re: Inserting a pushpin on a Image

    Qt Code:
    1. QPixmap pixcell(":/pin30_red.png");
    2. lbl->pixcell=new QPixmap(250,250);
    3.  
    4. //lbl->setPixmap(pixcell);
    5. pait=new QPainter(&pixcell);
    6. //pait->begin(pixcell);
    7. pait->fillRect(pixcell.rect(),Qt::transparent);
    8. pait->drawPixmap(250,250,&pixcell);
    9. pait->end();
    10. //lbl->setPixmap(pixcell);
    11. //pixcell.fill(lbl,250,250);
    12. lbl->setPixmap(pixcell);
    To copy to clipboard, switch view to plain text mode 

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

  16. #14
    Join Date
    Sep 2013
    Posts
    107
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default Re: Inserting a pushpin on a Image

    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
    Qt Code:
    1. QPixmap pixcell(":/pin30_red.png");
    2.  
    3. QPainter pait(&pixcell);
    4. pait.fillRect(pixcell.rect(),Qt::transparent);
    5. pait.drawPixmap(75,75,100,100,pixcell);
    6. pait.end();
    7. lbl->setPixmap(pixcell);
    To copy to clipboard, switch view to plain text mode 

    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.

  17. #15
    Join Date
    Sep 2013
    Posts
    107
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default Re: Inserting a pushpin on a Image

    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..

  18. #16
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Inserting a pushpin on a Image

    A complete simple example showing one way to do it (slightly different to my explanation above):
    Qt Code:
    1. #include <QApplication>
    2. #include <QWidget>
    3. #include <QPainter>
    4. #include <QPixmap>
    5. #include <QDebug>
    6.  
    7. class Widget: public QWidget {
    8. Q_OBJECT
    9. public:
    10. Widget(QWidget *p = 0): QWidget(p) {
    11. setFixedSize(QSize(512, 512));
    12. background.load("background_512x512.png");
    13. marker.load("marker_16x16.png");
    14. }
    15.  
    16. void setMarkedPoint(const QPoint &point) {
    17. markedPoint = point;
    18. update();
    19. }
    20. protected:
    21. void paintEvent(QPaintEvent *event) {
    22. QPainter p(this);
    23. p.drawPixmap(0, 0, background);
    24. if (!markedPoint.isNull())
    25. p.drawPixmap(markedPoint, marker);
    26. }
    27.  
    28. private:
    29. QPixmap background;
    30. QPixmap marker;
    31. QPoint markedPoint;
    32. };
    33.  
    34. int main(int argc, char *argv[]) {
    35. QApplication app(argc, argv);
    36.  
    37. Widget w;
    38. w.show();
    39. w.setMarkedPoint(QPoint(100, 100));
    40. return app.exec();
    41. }
    42. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    You need to provide the two images.

  19. The following user says thank you to ChrisW67 for this useful post:

    Vivek1982 (3rd December 2013)

  20. #17
    Join Date
    Sep 2013
    Posts
    107
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default Re: Inserting a pushpin on a Image

    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
    Attached Files Attached Files
    Last edited by Vivek1982; 3rd December 2013 at 07:29.

Similar Threads

  1. QLineEdit inserting from right to left
    By allyxcristiano in forum Newbie
    Replies: 4
    Last Post: 21st September 2015, 11:05
  2. Inserting Record
    By Nefastious in forum Newbie
    Replies: 3
    Last Post: 20th October 2009, 04:28
  3. Inserting PDF metadata
    By Randria in forum Qt Programming
    Replies: 2
    Last Post: 18th May 2009, 10:18
  4. Inserting Table
    By dreamer in forum Qt Programming
    Replies: 5
    Last Post: 16th May 2008, 10:10
  5. Inserting Image into a QTextBox
    By ashukla in forum Qt Programming
    Replies: 7
    Last Post: 15th September 2007, 11:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.