KeyWatcher(按键监控)
添加图片到widget
//添加图像 void Beginner::addimg(int num, int x, int y){ img[num] = new QLabel(this); QString name[41] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "Ctrl", "LeftShift", "RightShift", "Enter", "Direction" }; img[num]->setPixmap(QPixmap(("imgs/"+name[num]+".jpg"))); if (num == 37 || num == 38){ img[num]->setGeometry(QRect(x, y, 83, 34)); }else if (num == 39){ img[num]->setGeometry(QRect(x, y, 64, 34)); }else if (num == 40){ img[num]->setGeometry(QRect(x, y, 112, 39)); }else{ img[num]->setGeometry(QRect(x, y, 35, 34)); } }
//添加所有图像 void Beginner::addimgs(){ int currentHeight = 50; int row = 0; if (key[40]){ addimg(40, 15, currentHeight); currentHeight += 45; } for (int i = 37; i < 40; i++){ if (key[i]){ addimg(i, 15, currentHeight); currentHeight += 40; } } for (int j = 0; j < 37; j++){ if (key[j]){ if (row == 3){ row = 0; currentHeight += 40; addimg(j, 15, currentHeight); }else{ addimg(j, 15 + 40 * row, currentHeight); row++; } } } }
//添加标签 void Beginner::addlabel(int num, int x, int y){ label[num] = new QLabel(this); QString name[44] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "Ctrl", "左Shift", "右Shift", "回车", "上键", "下键", "左键", "右键" }; label[num]->setText((name[num]+":0次")); label[num]->setGeometry(QRect(x, y, 110, 20)); }
//添加所有标签 void Beginner::addlabels(){ int currentHeight = 50; currentHeight += 40 * ((linenum + 2) / 3); if (key[40]){ currentHeight += 45; } currentHeight += 20; if (key[40]){ addlabel(40, 15, currentHeight); currentHeight += 20; addlabel(41, 15, currentHeight); currentHeight += 20; addlabel(42, 15, currentHeight); currentHeight += 20; addlabel(43, 15, currentHeight); currentHeight += 20; } for (int i = 0; i < 40; i++){ if (key[i]){ addlabel(i, 15, currentHeight); currentHeight += 20; } } } |