/
widget.cpp
40 lines (36 loc) · 978 Bytes
/
widget.cpp
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
#include "widget.h"
#include "ui_widget.h"
#include <iostream>
#include <QDebug>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
loadIcons();
}
Widget::~Widget()
{
delete ui;
}
///
/// \brief Widget::loadIcons
/// load all icons from items.json
void Widget::loadIcons() {
QFile file;
QString txt;
file.setFileName(":/resources/items.json");
file.open(QIODevice::ReadOnly | QIODevice::Text);
txt = file.readAll();
file.close();
// parse JSON
QJsonDocument doc = QJsonDocument::fromJson(txt.toUtf8());
QJsonObject obj = doc.object();
for (auto it = obj.begin(); it != obj.end(); ++it) {
QCheckBox* check = new QCheckBox();
check->setText((*it).toObject().value("complete_name").toString());
check->setIcon(QIcon((*it).toObject().value("icon").toString()));
check->setIconSize(QSize(50,50));
ui->gridLayout->addWidget(check);
}
}