Results 1 to 7 of 7

Thread: how to mark a point on image.Image is already draw on QLabel and set using setPixmap

  1. #1
    Join Date
    Sep 2009
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  4. #4
    Join Date
    Sep 2009
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default 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:pen()
    {
    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.......

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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:

    Qt Code:
    1. void Widget::paintEvent(QPaintEvent * event) {
    2. //this will draw your widget, and therefore the label too
    3. QWidget::paintEvent(event);
    4.  
    5. //then draw your point
    6. Qpainter painter(this);
    7. painter.drawPoint(x, y);
    8. }
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by scascio; 20th September 2009 at 16:35.

  7. The following user says thank you to scascio for this useful post:

    bpatel (21st September 2009)

  8. #7
    Join Date
    Sep 2009
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to mark a point on image.Image is already draw on QLabel and set using setPix

    @above
    tbahks yaar for reply

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.