clicklabel: Add right button click signal

This commit is contained in:
Albert S. 2021-03-07 21:12:50 +01:00
parent 9ca1809d67
commit 4c2967a547
2 changed files with 15 additions and 10 deletions

View File

@ -3,9 +3,13 @@
void ClickLabel::mousePressEvent(QMouseEvent *event) void ClickLabel::mousePressEvent(QMouseEvent *event)
{ {
if(event->button() == Qt::LeftButton) if(event->button() == Qt::LeftButton)
{ {
emit leftClick(); emit leftClick();
} }
return QLabel::mousePressEvent(event); if(event->button() == Qt::RightButton)
{
emit rightClick();
}
return QLabel::mousePressEvent(event);
} }

View File

@ -1,17 +1,18 @@
#ifndef CLICKLABEL_H #ifndef CLICKLABEL_H
#define CLICKLABEL_H #define CLICKLABEL_H
#include <QLabel> #include <QLabel>
#include <QMenu>
class ClickLabel : public QLabel class ClickLabel : public QLabel
{ {
Q_OBJECT Q_OBJECT
public: public:
using QLabel::QLabel; using QLabel::QLabel;
signals: signals:
void leftClick(); void leftClick();
void rightClick();
protected: protected:
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
}; };
#endif // CLICKLABEL_H #endif // CLICKLABEL_H