shivcena
shivcena

Reputation: 2053

How to implement multiple click event for a image in qt

In my application I implemented click event for label, that works fine, but I want to implement multiple click events for a single image. For better understanding please refer below:

enter image description here

The above is the single image and I want to implement click events for the left and right side, how can I do this?

Upvotes: 0

Views: 384

Answers (2)

Igor
Igor

Reputation: 1059

class Label: public QWidget
{
public: 
    virtual void mousePressEvent(QMouseEvent * event) Q_DECL_OVERRIDE
    {
        if( m_leftArrowArea.contains( event->pos() ) )
        {
            //Handle left arrow action
        }
        else if( m_rightArrowArea.contains( event->pos() ) )
        {
            //Handle right arrow action
        }
    }


private:
    QRect m_leftArrowArea;
    QRect m_rightArrowArea;
}

Upvotes: 2

adnan kamili
adnan kamili

Reputation: 9465

On click you can get the relative co-ordinates of the mouse using which you can calculate the distance of mouse click from the left side of the image, using which you can distinguish click on different parts of the image.

Upvotes: 1

Related Questions