Qt: QFileDialog 打开对话框,选择图片,show在QLabel上

    技术2025-04-18  20

    最近有这样一个需求:点击按钮打开对话框选择图片并显示在UI上 getOpenFileName()函数参数填入文件路径,返回选中文件的路径

    #include<QFileDialog> void on_pushButton_clicked() { QString curPath=QDir::currentPath();//获取当前路径 QString str=QFileDialog::getOpenFileName(this,"打开文件",curPath); // QString str=QFileDialog::getOpenFileName(this,"打开文件",".");//"." 代表程序运行目录 // QString str=QFileDialog::getOpenFileName(this,"打开文件","/");//"/" 代表当前盘符的根目录 qDebug()<<str;//E:\project\Camerasensor\AT_VI_V5.6.0.12_Win64\GoldenTool\1.bmp //show图片 ui->label_PicHK->setPixmap(QPixmap(str)); }
    Processed: 0.011, SQL: 9