Qt显示PDF方法

Qt显示PDF方法
效果图

 

1.UI界面使用treeView控件,再在treeview上显示pdf文件

void MainWindow::init()

    appPath=QCoreApplication::applicationDirPath();//首先在头文件中把appPath定义为全局变量(.exe文件所在路径)
    model = new QFileSystemModel();
    model->setRootPath(appPath);    
    filePath=appPath+"/studyFile";//所要展示的pdf文件所在文件夹
    ui->treeView->setModel(model);
    ui->treeView->setRootIndex(model->index(filePath));

}

2.建立treeview双击事件

void MainWindow::on_treeView_doubleClicked(const QModelIndex &index)
{ if(process)
{        process->close();    }
    QString path=model->filePath(index);
    process->start("hh.exe "+path);
    process->waitForStarted();
}