QT图像质量双盲测试小软件的编写学习(3)

用户选择一幅质量好的图片,点击之后记录图片A1(B1)到TXT文件中,点击下一组按钮,出现下一组图,重复该过程。
设置单选控件以便用户选择左图还是右图,并设置下一组按钮以便换图、记录选择的图片和显示最后结果。

(1)设置单选控件的外形和点击后的颜色。

ui->radioButton->setStyleSheet("QRadioButton::indicator {width:15px;height:15px;border-radius:7px}"
                                       "QRadioButton::indicator:checked {background-color:blue;border: 2px solid white;}"
                                   "QRadioButton::indicator:unchecked {background-color:white;border: 2px solid white;}"

                                       );

    ui->radioButton_2->setStyleSheet("QRadioButton::indicator {width:15px;height:15px;border-radius:7px}"
                                       "QRadioButton::indicator:checked {background-color:blue;border: 2px solid white;}"
                                     "QRadioButton::indicator:unchecked {background-color:white;border: 2px solid white;}"

                                       );
                                       

(2)设置下一组按钮,实现换图、记录选择的图片。

void DisplayInterface::on_pushButton_next_clicked()
{
    
    //根据选择的图片,增加对应的计数
    //如果随机数是0,并且左边的单选按钮被选中,表明A文件夹里的图片被选中,记录图片名。
    if(randomNumber==0)
    {
        if(ui->radioButton->isChecked())
       { ++A_count;
        QFile f(dirAPath+"/"+"图片选择情况.txt");//在图像文件夹里添加txt文件
        f.open(QIODevice::Append);//txt文件末尾追加字符
        //为了记录成A1/A2/A3...
        QString str="A"+QString::number(current_img_index)+"/";
        char* ch;
        QByteArray ba=str.toLatin1();
        ch=ba.data();
        f.write(ch);
        //记录成A/
        // f.write("A/");
        f.close();}
        else// 如果随机数是0,而右边的单选按钮被选中,表明B文件夹里的图片被选中,记录图片名。
        {
            QFile f(dirAPath+"/"+"图片选择情况.txt");
            f.open(QIODevice::Append);
            QString str1="B"+QString::number(current_img_index)+"/";
            char* ch1;
            QByteArray ba=str1.toLatin1();
            ch1=ba.data();
            f.write(ch1);
            //f.write("B/");
            f.close();
        }


    }
    else if(randomNumber==1)// //如果随机数是1,并且右边的单选按钮被选中,表明A文件夹里的图片被选中,记录图片名。
    {
        if(ui->radioButton_2->isChecked())
          {  ++A_count;
        QFile f(dirAPath+"/"+"图片选择情况.txt");
        f.open(QIODevice::Append);
        QString str="A"+QString::number(current_img_index)+"/";
        char* ch;
        QByteArray ba=str.toLatin1();
        ch=ba.data();
        f.write(ch);
        f.close();}
        else// 如果随机数是1,而左边的单选按钮被选中,表明B文件夹里的图片被选中,记录图片名。
        {
            QFile f(dirAPath+"/"+"图片选择情况.txt");
            f.open(QIODevice::Append);
            QString str1="B"+QString::number(current_img_index)+"/";
            char* ch1;
            QByteArray ba=str1.toLatin1();
            ch1=ba.data();
            f.write(ch1);
            f.close();
        }

    }
    qDebug()<<"A_count:"<<A_count<<endl;
    QString Acount=QString::number(A_count,10);
    QString Totalcount=QString::number(total_image_count,10);

    if(current_img_index<total_image_count){
        show_next_image(dirAPath,dirBPath);
    }
    //否则current_img_index>=total_image_count
    //显示第三个界面,显示结果
   else if(current_img_index>=total_image_count)
    {
        this->hide();
        QFile f(dirAPath+"/"+"图片选择情况.txt");
        f.open(QIODevice::Append);
        f.write("\r\n");
        f.close();
        emit show_resultpage(Acount, Totalcount);
    }

}

3.和前面一样,当最后一组图片显示完毕,直接转到结果页面。
displayinterface.h中

signals:
    void show_resultpage(const QString&,const QString&);

resultpage.h中

private slots:
 void Show_Resultpage(const QString&,const QString&);

main.cpp中

QObject::connect(&displayInterface,SIGNAL(show_resultpage(const QString&,const QString&)),
                     &resultPage,SLOT(Show_Resultpage(const QString&,const QString&)));

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值