June 2018
Intermediate to advanced
348 pages
8h 45m
English
Let's write the header file my_qlabel.h to declare the class my_QLabel:
#include <QLabel>
#include <QMouseEvent>
class my_QLabel : public QLabel
{
Q_OBJECT
public:
explicit my_QLabel(QWidget *parent = nullptr);
void mouseMoveEvent(QMouseEvent *evt);
void mousePressEvent(QMouseEvent* evt);
void leaveEvent(QEvent* evt);
int x, y;
signals:
void Mouse_Pressed();
void Mouse_Position();
void Mouse_Left();
};
QLabel and QMouseEvent are defined under the included libraries, <QLabel> and <QMouseEvent>. The class is derived from QLabel to inherit its default behavior, and QObject is propertied to handle the signaling mechanism.
In the private section of the header file, we have added a Q_OBJECT macro to notify the MOC that ...
Read now
Unlock full access