QT中循环显示图片和简单的显示图片

请关注我的github

https://github.com/linqiaozhou
以下实例代码不久后将会上传到我的github
这是我最近一个项目中的部分代码
//以下是简单的在QT中显示图片的代码
this->imageOrg = new QImage();

    if(fileName != "")

    {

        if(imageOrg->load(fileName))

        {

            this->scene = new QGraphicsScene;

            *imageOrg=imageOrg->scaled(ui->View1->width()-,ui->View1->height()-,Qt::IgnoreAspectRatio);

            scene->addPixmap(QPixmap::fromImage(*imageOrg));

            ui->View1->setScene(scene);

           //ui->graphicsView->resize(image->width() + 10, image->height() + 10);

            ui->View1->show();

        }

    }

}
//循环显示图片的代码
void  MainWindow::autoplay()    //自动播放函数
{
QString fileName = QFileDialog::getOpenFileName(
this, "Open Image File",
".",
"Image files (*.bmp *.jpg *.pbm *.pgm *.png *.ppm *.xbm *.xpm);;All files (*.*)");
if(fileName != "")
{
ui->vedioLabel->setPixmap(fileName);
update();
} //以下步骤得到上层路径并求得图像序列号
int len=fileName.length()-;
while(fileName[len]!='/')
{
len--;
}
stringstream os;
string s=fileName.toStdString();
os<<s[len+];
os<<s[len+];
os>>indexVedio;
os.str("");
QString fileDir(len);
for(int i=;i
{
fileDir[i]=fileName[i];
} imgDirVideo.setPath(fileDir);
QStringList filter ;
filter << "*.jpg" << "*.bmp" << "*.jpeg" << "*.png" << "*.xpm" ;
imgListVideo =imgDirVideo.entryList(filter, QDir::Files |QDir::NoSymLinks,QDir::Name) ; timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(cdPicture()));
// QString framRate=ui->text3->toPlainText();
timer->start();//定时器,每隔100MS秒刷新 } //下面的子函数更改显示的帧数
void MainWindow::cdPicture()
{
//pixImage.load(imgDirVideo.absolutePath() + QDir::separator()+ imgListVideo.at(1)); indexVedio++;
if(indexVedio==MaxIndex)
{
if (timer->isActive())
{
timer->stop(); } QMessageBox::information(this,"End","The Last Frame");
return ;
}
ui->vedioLabel->setPixmap(imgDirVideo.absolutePath() + QDir::separator()+ imgListVideo.at(indexVedio));
update();
}
 
QT中信号与槽的简单示例:
private slots:

      void on_slotOpenImage_triggered(); //信号槽

connect(ui->OpenImageBtn,SIGNAL(clicked()), this, SLOT(on_slotOpenImage_triggered()));
上一篇:ECMAScript6 Generator & async


下一篇:七、在U-boot中让LCD显示图片