-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQHoverLabel.h
66 lines (54 loc) · 1.67 KB
/
QHoverLabel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef DEF_QHOVERLABEL_H
#define DEF_QHOVERLABEL_H
#include "QStringPlus.h"
#include "QPlus.h"
#include "main.h"
#include <QLabel>
#include <QtGlobal>
class QHoverLabel : public QLabel
{
Q_OBJECT
public:
QHoverLabel(QString path, QString name, bool isChoosen = false, QWidget* parent = nullptr) : QLabel(parent)
{
m_isChoosen = isChoosen;
if(!m_isChoosen)
{
setCursor(Qt::PointingHandCursor);
m_notHoverPixmap = getQPixmap(path + ".png");
}
m_hoverPixmap = getQPixmap(path + "Hover.png");
setPixmap(m_isChoosen ? m_hoverPixmap : m_notHoverPixmap);
QSize s = m_hoverPixmap.size();
setMaximumSize(s.width(), s.height()); // otherwise QLabel bounding box goes crazy
setToolTip(firstUppercase(translator.translate("resources", name.toStdString().c_str())));
}
// https://wiki.qt.io/Clickable_QLabel
signals:
void clicked();
protected:
void mousePressEvent(QMouseEvent* event) override
{
Q_UNUSED(event) // can't do another way ?
if(!m_isChoosen)
emit clicked();
}
void enterEvent(QEnterEvent* ev) override
{
Q_UNUSED(ev)
if(!m_isChoosen)
setPixmap(m_hoverPixmap);
//QLabel::enterEvent(ev);
}
void leaveEvent(QEvent* ev) override
{
Q_UNUSED(ev)
if(!m_isChoosen)
setPixmap(m_notHoverPixmap);
}
private:
bool m_isChoosen;
QPixmap m_notHoverPixmap,
m_hoverPixmap;
};
#endif