hc
2025-02-14 bbb9540dc49f70f6b703d1c8d1b85fa5f602d86e
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
67
68
#include "basewidget.h"
#include <QStyleOption>
#include <QPainter>
 
static int _id_widget = 0;
 
BaseWidget::BaseWidget(QWidget *parent) : QWidget(parent)
{
#ifndef DEVICE_EVB
    setWindowFlags(Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground, true);
#endif
    setMouseTracking(true);
}
 
void BaseWidget::paintEvent(QPaintEvent *)
{
    /* Slove the problem which 'setStyleSheet' and 'Q_OBJECT' can co-exist
       The below code used to repaint widgets when change became. */
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
 
void BaseWidget::setBackgroundColor(int rValue, int gValue, int bValue)
{
    _id_widget++;
    QString styleStr;
 
    setObjectName(QString::number(_id_widget));
    styleStr.append("#").append(QString::number(_id_widget)).append("{background-color:rgb(")
            .append(QString::number(rValue)).append(",")
            .append(QString::number(gValue)).append(",")
            .append(QString::number(bValue)).append(");")
            .append("}");
 
    setStyleSheet(styleStr);
}
 
void BaseWidget::setWidgetFontBold(QWidget *widget)
{
    QFont font = widget->font();
    font.setBold(true);
    widget->setFont(font);
}
 
void BaseWidget::setWidgetFontSize(QWidget *widget, int size)
{
    QFont font = widget->font();
    font.setPixelSize(size);
    widget->setFont(font);
}
 
void BaseWidget::mousePressEvent(QMouseEvent *e)
{
    QWidget::mousePressEvent(e);
}
 
void BaseWidget::mouseMoveEvent(QMouseEvent *e)
{
    QWidget::mouseMoveEvent(e);
}
 
void BaseWidget::mouseReleaseEvent(QMouseEvent *e)
{
    QWidget::mouseReleaseEvent(e);
}