Results 1 to 14 of 14

Thread: QPaint - Saving coordinates of 2 mouse clicks and the drawing line between them

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2013
    Posts
    58
    Thanks
    26
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Question QPaint - Saving coordinates of 2 mouse clicks and the drawing line between them

    Good Day,

    //I'm fairly proficient in qt -> got some problems with interactive programming as:

    1) I created a simple label
    2) Uploaded Image to Label
    3) using mouseEvents & paintEvent was able to create point on Image
    4) MY PROBLEM: the 2nd mouse click! //& store 2nd point where?

    User needs to click twice to get 2 points(line will be drawn between them, however everytime in the running program! when I click for a second time, the initial point becomes the new point.

    some att code:
    void label::mousePressEvent(QMouseEvent *event)
    {
    paintFlag = 0;
    if(event->button()==Qt::LeftButton)
    {
    this->x = ev->x();
    this->y = ev->y();
    //store 1st point
    x1 = x;
    y1 = y;
    emit Mouse_Pressed();
    paintFlag = 1;

    //Mouse Pressed Again! 2nd point
    x2 = x;
    y2 = y;
    emit Mouse_Pressed();
    }

    }

    paintEvent:
    QPainter painter(this);
    QPen paintpen(Qt::red);
    paintpen.setWidth(4);

    QPoint p1;
    p1.setX(x1);
    p1.setY(y1);

    painter.setPen(paintpen);
    painter.drawPoint(p1);

    }


    Any ideas on my problem... what am i not seeing!
    Thanks
    Last edited by ebsaith; 10th June 2013 at 12:08.

Similar Threads

  1. Replies: 3
    Last Post: 22nd February 2013, 19:56
  2. Replies: 3
    Last Post: 12th May 2010, 13:11
  3. Generating Mouse Clicks
    By Ebonair in forum Qt Programming
    Replies: 2
    Last Post: 4th July 2009, 18:20
  4. traversing tree using mouse clicks
    By krishna.bv in forum Qt Programming
    Replies: 3
    Last Post: 22nd December 2006, 09:15
  5. Detecting mouse clicks outside of widget
    By init2null in forum Qt Programming
    Replies: 2
    Last Post: 5th May 2006, 19:16

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.