-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey_board.cpp
97 lines (72 loc) · 2.86 KB
/
key_board.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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "key_board.h"
#include "ui_key_board.h"
#include<QString>
#include<QFile>
key_board::key_board(int o) :
// QWidget(parent),这句加了之后就错了,似乎不能再设立父类了
ui(new Ui::key_board)
{
ui->setupUi(this);
QFile file(":/res/octave_white.qss"); //统一给全音设置样式
//只读方式打开文件
file.open(QFile::ReadOnly);
//读取文件的所有内容,并转换成QString类型
QString styleSheet = tr(file.readAll());
QString str1=QString("C %1").arg(o);
ui->pushButton_C->setText(str1);
//给当前对象设置样式表
// ui->pushButton_C->setStyleSheet(styleSheet);//C在样式表,不用再设置
QString str3=QString("D %1").arg(o);
ui->pushButton_D->setText(str3);
//给当前对象设置样式表
ui->pushButton_D->setStyleSheet(styleSheet);
QString str5=QString("E %1").arg(o);
ui->pushButton_E->setText(str5);
//给当前对象设置样式表
ui->pushButton_E->setStyleSheet(styleSheet);
QString str6=QString("F %1").arg(o);
ui->pushButton_F->setText(str6);
//给当前对象设置样式表
ui->pushButton_F->setStyleSheet(styleSheet);
QString str8=QString("G %1").arg(o);
ui->pushButton_G->setText(str8);
//给当前对象设置样式表
ui->pushButton_G->setStyleSheet(styleSheet);
QString str10=QString("A %1").arg(o);
ui->pushButton_A->setText(str10);
//给当前对象设置样式表
ui->pushButton_A->setStyleSheet(styleSheet);
QString str12=QString("B %1").arg(o);
ui->pushButton_B->setText(str12);
//给当前对象设置样式表
ui->pushButton_B->setStyleSheet(styleSheet);
//关闭qss文件
file.close();//其实不用写,离开作用域自动关闭
/***********************************************************************************************/
QFile file1(":/res/octave_black.qss"); //统一给半音设置样式(C1,D1这种都是表示C#,D#)
//只读方式打开文件
file1.open(QFile::ReadOnly);
//读取文件的所有内容,并转换成QString类型
QString styleSheet1 = tr(file1.readAll());
QString str2=QString("C#%1").arg(o);
ui->pushButton_C1->setText(str2);
ui->pushButton_C1->setStyleSheet(styleSheet1);
QString str4=QString("D#%1").arg(o);
ui->pushButton_D1->setText(str4);
ui->pushButton_D1->setStyleSheet(styleSheet1);
QString str7=QString("F#%1").arg(o);
ui->pushButton_F1->setText(str7);
ui->pushButton_F1->setStyleSheet(styleSheet1);
QString str9=QString("G#%1").arg(o);
ui->pushButton_G1->setText(str9);
ui->pushButton_G1->setStyleSheet(styleSheet1);
QString str11=QString("A#%1").arg(o);
ui->pushButton_A1->setText(str11);
ui->pushButton_A1->setStyleSheet(styleSheet1);
//关闭qss文件
file1.close();
}
key_board::~key_board()
{
delete ui;
}