qt_demoe/ui/styledemo/frmmain.cpp

82 lines
1.9 KiB
C++
Raw Normal View History

2021-09-19 03:44:22 +00:00
#include "frmmain.h"
2019-09-29 12:43:40 +00:00
#include "ui_frmmain.h"
2021-09-19 03:44:22 +00:00
#include "head.h"
2019-09-29 12:43:40 +00:00
frmMain::frmMain(QWidget *parent) : QMainWindow(parent), ui(new Ui::frmMain)
{
ui->setupUi(this);
this->initForm();
}
frmMain::~frmMain()
{
delete ui;
}
void frmMain::initForm()
{
2021-09-19 03:44:22 +00:00
ui->rbtn1->setChecked(true);
ui->ck2->setChecked(true);
ui->ck3->setCheckState(Qt::PartiallyChecked);
2021-11-25 12:57:08 +00:00
ui->textEdit->setText("QQ517216493\nWXfeiyangqingyun");
ui->treeWidget->expandAll();
int rowHeight = 23;
ui->tableWidget->horizontalHeader()->setFixedHeight(rowHeight);
2021-12-27 01:38:55 +00:00
ui->tableWidget->verticalHeader()->setDefaultSectionSize(rowHeight);
2021-11-25 12:57:08 +00:00
//加载鼠标右键菜单翻译文件
QTranslator *translator1 = new QTranslator(qApp);
if (translator1->load(":/qm/qt_zh_CN.qm")){
qApp->installTranslator(translator1);
}
//加载富文本框鼠标右键菜单翻译文件
QTranslator *translator2 = new QTranslator(qApp);
if (translator2->load(":/qm/widgets.qm")) {
qApp->installTranslator(translator2);
}
on_btnStyle1_clicked();
2019-09-29 12:43:40 +00:00
}
2021-11-25 12:57:08 +00:00
void frmMain::loadStyle(const QString &qssFile)
2021-11-17 07:33:19 +00:00
{
//加载样式表
2021-11-25 12:57:08 +00:00
QString qss;
QFile file(qssFile);
2021-11-17 07:33:19 +00:00
if (file.open(QFile::ReadOnly)) {
//用QTextStream读取样式文件不用区分文件编码 带bom也行
QStringList list;
QTextStream in(&file);
//in.setCodec("utf-8");
while (!in.atEnd()) {
QString line;
in >> line;
list << line;
}
2021-11-25 12:57:08 +00:00
file.close();
2021-11-17 07:33:19 +00:00
qss = list.join("\n");
QString paletteColor = qss.mid(20, 7);
qApp->setPalette(QPalette(paletteColor));
qApp->setStyleSheet(qss);
}
}
2021-11-25 12:57:08 +00:00
void frmMain::on_btnStyle1_clicked()
2021-11-17 07:33:19 +00:00
{
2021-11-25 12:57:08 +00:00
loadStyle(":/qss/lightblue.css");
2021-11-17 07:33:19 +00:00
}
2021-11-25 12:57:08 +00:00
void frmMain::on_btnStyle2_clicked()
2019-09-29 12:43:40 +00:00
{
2021-12-15 05:21:29 +00:00
loadStyle(":/qss/flatgray.css");
2019-09-29 12:43:40 +00:00
}
2021-11-25 12:57:08 +00:00
void frmMain::on_btnStyle3_clicked()
2019-09-29 12:43:40 +00:00
{
2021-12-15 05:21:29 +00:00
loadStyle(":/qss/blacksoft.css");
2019-09-29 12:43:40 +00:00
}