; ; ; ; * 7 * @brief set_image 将图像设置到label上,图像自动根据label的大小来缩放 8 * @param label 9 * @param image set_image(QLabel *label, const QPixmap &image) { 12 float ratio(0.); 13 ratio = 1. * label->width() / image.width(); 14 ratio = fmin( 1. * label->height() / image.height(), ratio ); 15 QPixmap m = image.scaled(static_cast<int>(image.width() * ratio), static_cast<int>(image.height() * ratio)); 16 label->setPixmap(m); 17 } set_image(QLabel *label, const std::string image_path) { 20 QPixmap image(image_path.c_str()); 21 set_image(label, image); 22 } * 25 * @brief MainWindow::display \n 26 * 根据系统中的所有的变量来设置当前界面中的各个部分的内容 MainWindow::display() { (this->current_idx >= this->total_pair_num) { , , QMessageBox::Ok); 32 this->current_idx = this->total_pair_num - 1; 33 } 34 if (this->current_idx < 0) { , , QMessageBox::Ok); 36 this->current_idx = 0; 37 } ->ui->horizontalSlider_progress->setRange(0, this->total_pair_num - 1); 41 this->ui->horizontalSlider_progress->setValue(this->current_idx); ->ui->statusBar->showMessage(QString((std::to_string(+ std::to_string(this->total_pair_num)).c_str())); std::string image_name_1 = this->image_list_1[this->current_idx]; ) + 1); 49 std::string image_name_2 = this->image_list_2[this->current_idx]; ) + 1); 51 this->ui->label_image_name_1->setText(image_base_name_1.c_str()); 52 this->ui->label_image_name_2->setText(image_base_name_2.c_str()); set_image(this->ui->label_image_view_1, image_name_1); 56 set_image(this->ui->label_image_view_2, image_name_2); std::string show_image_name = UNKNOWN_FILE; 60 switch (this->annotation_list[this->current_idx]) { 61 case AnnoState::UNKNOWN: 62 show_image_name = UNKNOWN_FILE; 63 break; 64 case AnnoState::YES: 65 show_image_name = YES_FILE; 66 break; 67 case AnnoState::NO: 68 show_image_name = NO_FILE; 69 break; 70 case AnnoState::UNSURE: 71 show_image_name = UNSURE_FILE; 72 break; 73 } 74 set_image(this->ui->label_image_compare_status, show_image_name); 75 76 }
最开始我们定义了4个图片的路径。这可以是绝对路径或者相对路径。我们这里的路径设置的比较奇怪,在下面我们会讲到。
set_image负责将给定的图片绘制到QLabel上,为了显示的好看,图像会按照QLabel的尺寸来动态的缩放。这样就不会出现有个图像太大或太小的情况了。
display则是负责各个区域的绘制。
还差一步是保存结果: