如何在qt中为图像实现多次单击事件

时间:2015-09-19 05:56:23

标签: qt

在我的应用程序中,我为标签实现了click事件,工作正常,但我想为单个图像实现多个点击事件。为了更好地理解,请参阅以下内容:

enter image description here

以上是单张图片,我想实现左侧和右侧的点击事件,我该怎么做?

1 个答案:

答案 0 :(得分:2)

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;
}