File: qt_helpers.cpp

package info (click to toggle)
js8call 2.5.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,720 kB
  • sloc: cpp: 562,655; sh: 898; python: 132; ansic: 102; makefile: 4
file content (56 lines) | stat: -rw-r--r-- 1,420 bytes parent folder | download
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
#include "qt_helpers.h"

#include <QFont>
#include <QString>
#include <QStyle>
#include <QVariant>
#include <QWidget>

QString font_as_stylesheet(QFont const &font) {
    QString font_weight;
    switch (font.weight()) {
    case QFont::Thin:
        font_weight = "thin";
        break;
    case QFont::ExtraLight:
        font_weight = "extralight";
        break;
    case QFont::Light:
        font_weight = "light";
        break;
    case QFont::Normal:
        font_weight = "normal";
        break;
    case QFont::Medium:
        font_weight = "medium";
        break;
    case QFont::DemiBold:
        font_weight = "demibold";
        break;
    case QFont::Bold:
        font_weight = "bold";
        break;
    case QFont::ExtraBold:
        font_weight = "extrabold";
        break;
    case QFont::Black:
        font_weight = "black";
        break;
    }
    return QString{" font-family: %1;\n"
                   " font-size: %2pt;\n"
                   " font-style: %3;\n"
                   " font-weight: %4;\n"}
        .arg(font.family())
        .arg(font.pointSize())
        .arg(font.styleName())
        .arg(font_weight);
}

void update_dynamic_property(QWidget *widget, char const *property,
                             QVariant const &value) {
    widget->setProperty(property, value);
    widget->style()->unpolish(widget);
    widget->style()->polish(widget);
    widget->update();
}