QT从json文件中读取数据填充到QTabelView中

1.json文件

{
    "shortcutInfos": 
	[
        {
	        "shortcut":"F1",
	        "applyTo":"全局",
	        "command":"帮助"
        },
        {
	        "shortcut":"F2",
	        "applyTo":"全局",
	        "command":"信息"
        },
        {
	        "shortcut":"F3",
	        "applyTo":"全局",
	        "command":"配置"
        },
        {
	        "shortcut":"F4",
	        "applyTo":"全局",
	        "command":"窗口"
        },
        {
	        "shortcut":"F5",
	        "applyTo":"全局",
	        "command":"事件"
        }
	]
}

2.头文件 HelpDialog.h

#ifndef HELPDIALOG_H
#define HELPDIALOG_H

#include <QDialog>

namespace Ui {
class HelpDialog;
}

typedef struct _ShortcutInfo
{
	QString shortcut;
	QString applyTo;
	QString command;
}ShortcutInfo;

class QStandardItemModel;
class HelpDialog : public QDialog
{
	Q_OBJECT
public:
    explicit HelpDialog(QWidget *parent = 0);
    ~HelpDialog();
	void setModelContent();
	void initShortcutInfoList();
Q_SLOT void on_closeBtn_clicked();
private:
    Ui::HelpDialog *ui;
	QStandardItemModel* mModel;
	QList<ShortcutInfo> mShortcutInfoList;
};

#endif // HELPDIALOG_H

3.源文件 HelpDialog.cpp

#include "HelpDialog.h"
#include "ui_HelpDialog.h"
#include <QStandardItemModel>
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QDebug>
#include <QTextCodec>

HelpDialog::HelpDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::HelpDialog)
{
    ui->setupUi(this);
	setWindowFlags(Qt::FramelessWindowHint);
	//setWindowModality(Qt::WindowModal);
	ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
	ui->tableView->horizontalHeader()->setHighlightSections(false);
	ui->tableView->verticalHeader()->hide(); 
	ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); 
	//ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
	ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
	ui->tableView->setFocusPolicy(Qt::NoFocus);

	mModel = new QStandardItemModel(this);
	QStringList headList;
	headList << tr("Shortcut") << tr("Applies to:") << tr("Command");
	mModel->setHorizontalHeaderLabels(headList);
	
	setModelContent();

	ui->tableView->setModel(mModel);

	QString style = "QDialog{background-color:#1A1E30;border:1px solid #3D4C76;}"//
		"QLabel{"
		"color:#D0DFE6;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值