精华内容
下载资源
问答
  • QT 图片浏览器

    2012-07-02 18:16:02
    QT 图片浏览器 有报告,用于对代码做一些说明。
  • QT图片浏览器

    2012-07-03 19:42:25
    该代码是一个基于Linux的QT图片浏览器,可下载到开发板上运行,具有查看上一个、下一个、循环播放、旋转、扭曲、放大缩小等功能,适合初学者
  • Qt图片浏览器

    2019-03-29 17:26:51
    qt写的图片浏览器源码,可以打开图片,进行放大缩小正常尺度,界面纯代码编写。
  • qt图片浏览器

    2014-12-12 11:25:25
    基于QT平台的图片浏览器,包括按钮切换,触屏切换,自动播放等功能
  • 原创Qt图片浏览器,图片分页显示,集成图片缩放、删除等功能
  • Linux QT 图片浏览器

    2012-09-20 09:47:31
    Linux QT 大作业,图片浏览器,可实现自动播放,放大,缩小,旋转等功能。
  • Graphics View Framework、Qt、多媒体、图片浏览器
  • QT 图片浏览器(二)

    千次阅读 2013-04-10 15:02:02
    前边所写的QT图片浏览器程序是在window下QT Creator环境中编写的,在window上面运行效果很正确,但是因为是需要在linux下面的QT环境中编译,所以在linux下面编译以后运行出现的效果却不是理想想过,现象是在打开...

    前边所写的QT图片浏览器程序是在window下QT Creator环境中编写的,在window上面运行效果很正确,但是因为是需要在linux下面的QT环境中编译,所以在linux下面编译以后运行出现的效果却不是理想想过,现象是在打开linux下面的图片以后,上下翻转不按文件夹中已经排列好的顺序显示,而是一个固定的另一个顺序,进而导致删除也不成功,最后更改了遍历打开图片所在文件夹下的全部图片这个功能函数的代码,换了一种遍历方法,最后得到了理想的效果。代码如下:

    csimagescan.cpp:

    #include "csimagescan.h"
    #include "ui_csimagescan.h"

    csImageScan::csImageScan(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::csImageScan)
    {
        ui->setupUi(this);
        position =0;
        left=0;
        right=0;
        num_Roll = 0;

        setWindowFlags(Qt::FramelessWindowHint);//去掉标题栏
        int screen_W=QApplication::desktop()->width();
        int screen_H=QApplication::desktop()->height();

        resize(screen_W,screen_H);
        //int win_W=width();
        //int win_H=height();
        //
        printf("abcdefghigk=====%d,------12345678910========%d-----------\n\n\n\n",screen_W,screen_H);
        /*
        QPushButton pbexit = new QPushButton(this);
        pbexit->setObjectName(QString::fromUtf8("pbexit"));
        pbexit->setGeometry(QRect(803,728,40,40));
        pbexit->setFocusPolicy(Qt::NoFocus);
        pbexit->setFlat(true);
        */
        ui->pre->setGeometry(523,728,40,40);
        ui->next->setGeometry(603,728,40,40);
        //ui->rotuteleft->setGeometry(203,728,40,40);
        //ui->rotuteright->setGeometry(283,728,40,40);
        ui->pbdelete->setGeometry(723,728,40,40);
        ui->pbexit->setGeometry(QRect(803,728,40,40));
        ui->rotuteleft->setEnabled(false);
        ui->rotuteright->setEnabled(false);

        QPixmap m_pixmap("res/pre.png");
        QIcon m_icon;
        m_icon.addPixmap(m_pixmap);
        ui->pre->setIcon(m_icon);
        ui->pre->setIconSize(QSize(40,40));

        m_pixmap.load("res/next.png");
        m_icon.addPixmap(m_pixmap);
        ui->next->setIcon(m_icon);
        ui->next->setIconSize(QSize(40,40));
    /*
        m_pixmap.load("res/left.png");
        m_icon.addPixmap(m_pixmap);
        ui->rotuteleft->setIcon(m_icon);
        ui->rotuteleft->setIconSize(QSize(60,60));

        m_pixmap.load("res/right.png");
        m_icon.addPixmap(m_pixmap);
        ui->rotuteright->setIcon(m_icon);
        ui->rotuteright->setIconSize(QSize(60,60));
    */
        m_pixmap.load("res/imgdelete.png");
        m_icon.addPixmap(m_pixmap);
        ui->pbdelete->setIcon(m_icon);
        ui->pbdelete->setIconSize(QSize(40,40));

        m_pixmap.load("res/exit.png");
        m_icon.addPixmap(m_pixmap);
        ui->pbexit->setIcon(m_icon);
        ui->pbexit->setIconSize(QSize(40,40));
    }

    csImageScan::~csImageScan()
    {
        delete ui;
    }


    /*
    void csImageScan::drawImageOnSrc(QString & str)
    {
        //
        ui->label->setPixmap(QPixmap(str));
        //
    }
    */

    //图片浏览对话框关闭按钮槽
    void csImageScan::on_pbexit_clicked()
    {
        this->close();
    }
    //打开图片浏览功能
    void csImageScan::on_open_clicked()
    {
        position =0;
        stringlist.clear();
        //   printf("%s\n",filepath.toAscii().constData());
        filepath = QFileDialog::getOpenFileName(NULL, QObject::tr("Open Image"), ".",
                                                QObject::tr("Image Files(*.jpg *.png *.bmp)"));

        filelist = filepath.split("/");
        filelist.removeLast ();
        folderpath = filelist.join("/");
        setpixmap(filepath);
        printf("-----%d------\n",position);
    }

    //遍历打开图片所在文件夹下的全部图片
    void csImageScan::Open_File()
    {
            QDir dir(folderpath);
            QFileInfoList fileList;
            QFileInfo curFile;
            QStringList filters;
            //filters << "*.jpg"<<"*.png";
            filters << "*.jpg"<<"*.png"<<"*.bmp";
            fileList=dir.entryInfoList(filters,QDir::Dirs|QDir::Files
                         |QDir::Readable|QDir::Writable
                         |QDir::Hidden|QDir::NoDotAndDotDot
                         ,QDir::Name);
            int i=0;
            if(fileList.size()>0)
            {
                //curFile=fileList[position];
                while(i<fileList.size())
                {
                    curFile=fileList[i];
                    if(filepath == curFile.filePath())
                        position = i;
                    stringlist<<curFile.filePath();
                    printf("----delete----%d----------\n",i);
                    printf("%s----\n",curFile.filePath().toAscii().constData());
                    //printf("%s----\n",filepath.toAscii().constData());
                    i++;
                }

            }
    }

    //图片前翻
    void csImageScan::on_pre_clicked()
    {
        left=0;
        right=0;
        num_Roll = 0;
        if(0 == stringlist.size())
        {
            printf("get pre image erron \n");
            return ;
        }
        position--;
        if(position<0)
        {
            position=stringlist.size()-1;
        }

        filepath = stringlist.at(position);
        setpixmap(filepath);
        printf("---pre----%d-------------------\n",position);
        printf("%s----\n",filepath.toAscii().constData());
    }

    //图片后翻
    void csImageScan::on_next_clicked()
    {
        left=0;
        right=0;
        num_Roll = 0;
        if(0 == stringlist.size())
        {
            printf("get next image erron \n");
            return ;
        }
        position++;
        if(position>stringlist.size()-1)
        {
            position=0;
        }
        filepath = stringlist.at(position);
        setpixmap(filepath);
        printf("---next----%d-------------------\n",position);
        printf("%s----\n",filepath.toAscii().constData());
    }
    //图片逆时针旋转
    void csImageScan::on_rotuteleft_clicked()
    {
        if(0 == stringlist.size())
        {
            printf("get next image erron \n");
            return ;
        }
        left=1;
        if(left==1&&right==1)
        {
            num_Roll--;
            //QImage image(stringlist.at(position));
            QMatrix matrix;
            //matrix.rotate(-90.0*num_Roll);
            matrix.rotate(-90.0);
            image = image.transformed(matrix,Qt::FastTransformation);
            pix = pix.fromImage(image);
            update();
        }
        else
        {
        num_Roll++;
        //QImage image(stringlist.at(position));
        image.load(stringlist.at(position));
        QMatrix matrix;
        matrix.rotate(-90.0*num_Roll);
        image = image.transformed(matrix,Qt::FastTransformation);
        pix = pix.fromImage(image);
        update();
        }

    }
    //图片顺时针旋转
    void csImageScan::on_rotuteright_clicked()
    {
        if(0 == stringlist.size())
        {
            printf("get next image erron \n");
            return ;
        }
        right=1;
        if(left==1&&right==1)
        {
            //num_Roll--;
            //QImage image(stringlist.at(position));
            QMatrix matrix;
            //matrix.rotate(90.0*num_Roll);
            matrix.rotate(90.0);
            image = image.transformed(matrix,Qt::FastTransformation);
            pix = pix.fromImage(image);
            update();
        }
        else
        {
        num_Roll++;
        //QImage image(stringlist.at(position));
        image.load(stringlist.at(position));
        QMatrix matrix;
        matrix.rotate(90.0*num_Roll);
        image = image.transformed(matrix,Qt::FastTransformation);
        pix = pix.fromImage(image);
        update();
        }
    }
    //图片删除
    void csImageScan::on_pbdelete_clicked()
    {
        if(stringlist.size() == 0)
            return;
        QMessageBox::StandardButton rb = QMessageBox::question(NULL,"Warning",
                     "Do you want to delete the picture?",QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
        if(rb == QMessageBox::Yes)
        {

            stringlist.takeAt(position);
            QDir dir(folderpath);
            QFileInfoList fileList;
            QFileInfo curFile;
            QStringList filters;
            filters << "*.jpg"<<"*.png"<<"*.bmp";
            fileList=dir.entryInfoList(filters,QDir::Dirs|QDir::Files
                         |QDir::Readable|QDir::Writable
                         |QDir::Hidden|QDir::NoDotAndDotDot
                         ,QDir::Name);
            if(fileList.size()>0)
            {
                curFile=fileList[position];
                QFile fileTemp(curFile.filePath());
                fileTemp.remove();
                fileList.removeAt(position);
                //QFile filetemp(curFile.filePath().remove(QString("_screen"), Qt::CaseSensitive));
                //filetemp.remove();
                printf("----delete----%d----------\n",position);
                printf("%s----\n",curFile.filePath().toAscii().constData());
            }
            if(0 == stringlist.size())
            {
                printf("get next image erron \n");
                return ;
            }
            else
            {
                filepath = stringlist.at(position);
                setpixmap(filepath);
            }
        }
    }
    //重绘事件
    void csImageScan::paintEvent ( QPaintEvent * )
    {
        QPainter painter(this);
        painter.drawPixmap(43,0,pix);
     }


    void csImageScan::setpixmap(QString imageName)
    {
        pix.load(imageName);
        update();
    }

    其他地方的代码完全相同。

    展开全文
  • 图片浏览器实现图片的翻转缩小放大停止前进等10个功能

    图片的功能


    源代码:

    wiget.h

    #ifndef WIDGET_H
    #define WIDGET_H
    #include <QPixmap>
    #include <QImage>
    #include <QPushButton>
    #include <QHBoxLayout>
    #include <QScrollArea>
    #include <QLabel>
    #include <QWidget>
    #include <QPalette>
    #include <QTimer>
    #include <QString>
    #include <QPainter>
    #include <QPaintEvent>
    #include <QDebug>
    #include <QFileDialog>
    #include <QStringList>
    #include <QMessageBox>
    #include <QDir>
    #include <QFile>
    namespace Ui {
    class Widget;
    }
     
    
    class Widget : public QWidget
    {
        Q_OBJECT  
    public:
        explicit Widget(QWidget *parent = 0);
        ~Widget();
        QLabel *label;
        QTimer *timer;
        QPixmap pix;
     
    
    private slots:
        void W_timergo();
        void W_go();
        void W_back();
        void W_close();
        void W_start();
        void W_stop();
        void W_max();
        void W_min();
        void W_flip();
        void W_delete();
        void W_open();
    private:
        Ui::Widget *ui;
    };
     
    
    #endif // WIDGET_H
     
    

    wiget.cpp

    #include "widget.h"
    #include "ui_widget.h"
    static int num;
    static int flag=1;
    QString image[3] = {":/prefix1/1.jpg",":/prefix1/2.jpg",":/prefix1/3.jpg"};
    Widget::Widget(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::Widget)
    {
        ui->setupUi(this);
        QPixmap pix;
     
    
        label = new QLabel;
        timer = new QTimer;
        QPalette palette;
     
    
        ui->scrollArea->setWidget(label);
        ui->scrollArea->setAlignment(Qt::AlignCenter);
     
    
        palette.setBrush(QPalette::Background,QBrush(QPixmap(":/prefix1/4.jpg")));
        this->setPalette(palette);
     
    
        connect(timer,SIGNAL(timeout()),this,SLOT(W_go()));
        connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(W_go()));
        connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(W_close()));
        connect(ui->pushButton_4,SIGNAL(clicked()),this,SLOT(W_start()));
        connect(ui->pushButton_5,SIGNAL(clicked()),this,SLOT(W_stop()));
        connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(W_back()));
        connect(ui->pushButton_6,SIGNAL(clicked()),this,SLOT(W_max()));
        connect(ui->pushButton_7,SIGNAL(clicked()),this,SLOT(W_min()));
        connect(ui->pushButton_8,SIGNAL(clicked()),this,SLOT(W_flip()));
        connect(ui->pushButton_9,SIGNAL(clicked()),this,SLOT(W_delete()));
        connect(ui->pushButton_10,SIGNAL(clicked()),this,SLOT(W_open()));
     
    
    }
    void Widget::W_timergo()
    {
       pix.load(image[num]);
       label->setPixmap(pix);
       if(num==2)
       {
            num = -1;
     
    
       }
       num++;
    }
    void Widget::W_go()
    {
        timer->stop();
        pix.load(image[num]);
        label->setPixmap(pix);
        if(num==2)
        {
             num = -1;
     
    
        }
        num++;
    }
    void Widget::W_back()
    {
        if(num < 0)
        {
            num = 2;
     
    
        }
        timer->stop();
        pix.load(image[num]);
        label->setPixmap(pix);
        num--;
     
    
    }
    void Widget::W_close()
    {
        this->close();
     
    
    }
    void Widget::W_start()
    {
     
    
         timer->start(2000);
     
    
    }
    void Widget::W_stop()
    {
        timer->stop();
    }
    void Widget::W_max()
    {
        timer->stop();
        float MaxX,MaxY;
        MaxX = pix.height();
        MaxY = pix.width();
     
    
        pix = pix.scaled(MaxX*2,MaxY*2,Qt::KeepAspectRatio);
        label->setPixmap(pix);
     
    
     
    
     
    
     
    
     
    
    }
    void Widget::W_min()
    {
        timer->stop();
        float MaxX,MaxY;
        MaxX = pix.height();
        MaxY = pix.width();
     
    
        pix = pix.scaled(MaxX/2,MaxY/2,Qt::KeepAspectRatio);
        label->setPixmap(pix);
     
    
    }
    void Widget::W_flip()
    {
     
    
        timer->stop();
        QMatrix leftmatrix;
        leftmatrix.rotate(90*flag);
        flag++;
        if(flag == 4)
        {
            flag = 0;
     
    
        }
        label->setPixmap(QPixmap(image[num]).transformed(leftmatrix,Qt::SmoothTransformation));
     
    
     
    
     
    
     
    
    }
    void Widget::W_delete()
    {
        timer->stop();
        QStringList list;
        list=QFileDialog::getOpenFileNames(this,"open image","/","*.jpg");
        qDebug()<<list.at(0);
        pix.load(list.at(0));
        label->setPixmap(pix);
        QMessageBox::StandardButton rb = QMessageBox::question(NULL,"Warning",
                        "Do you want to delete the picture?",QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
           if(rb == QMessageBox::Yes)
           {
     
    
     
    
               QFile::remove(list.at(0));//刪除文件
     
    
           }
    }
    void Widget::W_open()
    {
        timer->stop();
        QStringList list;
        list=QFileDialog::getOpenFileNames(this,"open image","/","*.jpg");
     
    
         qDebug()<<list.at(0);
        pix.load(list.at(0));
        label->setPixmap(pix);
    }
    Widget::~Widget()
    {
        delete ui;
    }
     main.cpp 
    

    #include "widget.h"
    #include <QApplication>
     
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        Widget w;
        w.show();
     
    
        return a.exec();
    }
     
    





    展开全文
  • QT 图片浏览器(一)

    万次阅读 2013-04-10 14:54:40
    这一段时间在做一个图片浏览器,实现图片左右浏览,图片删除,图片旋转的功能,在初期的时候我在window系统下面的QT Creator中编写代码,编写以后实现了以上所说的功能。虽然难度不是很大,但是在编写的时候由于能力...

    这一段时间在做一个图片浏览器,实现图片左右浏览,图片删除,图片旋转的功能,在初期的时候我在window系统下面的QT Creator中编写代码,编写以后实现了以上所说的功能。虽然难度不是很大,但是在编写的时候由于能力有限,也花费了我很多时间,希望这段代码对大家有所帮助

    由于ui文件没办法上传,所以只能讲ui文件的.h文件写在这里

    ui_csimagescan.h

     #include "csimagescan.h"

    #include "ui_csimagescan.h"
    csImageScan::csImageScan(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::csImageScan)
    {
        ui->setupUi(this);
        position =0;
        left=0;
        right=0;
        num_Roll = 0;
        //为前后翻转按钮,顺时针逆时针旋转按钮和删除按钮添加图标
        QPixmap m_pixmap("image/pre.png");//前翻转
        QIcon m_icon;
        m_icon.addPixmap(m_pixmap);
        ui->pre->setIcon(m_icon);
        ui->pre->setIconSize(QSize(60,60));
        m_pixmap.load("image/next.png");//后翻转
        m_icon.addPixmap(m_pixmap);
        ui->next->setIcon(m_icon);
        ui->next->setIconSize(QSize(60,60));
        m_pixmap.load("image/left.png");//逆时针
        m_icon.addPixmap(m_pixmap);
        ui->rotuteleft->setIcon(m_icon);
        ui->rotuteleft->setIconSize(QSize(60,60));
        m_pixmap.load("image/right.png");//顺时针
        m_icon.addPixmap(m_pixmap);
        ui->rotuteright->setIcon(m_icon);
        ui->rotuteright->setIconSize(QSize(60,60));
        m_pixmap.load("image/imgdelete.png");//删除
        m_icon.addPixmap(m_pixmap);
        ui->pbdelete->setIcon(m_icon);
        ui->pbdelete->setIconSize(QSize(60,60));
    }
    csImageScan::~csImageScan()
    {
        delete ui;
    }
    void csImageScan::on_open_clicked()//打开对话框选择图片
    {
        position =0;
        stringlist.clear();
        //   printf("%s\n",filepath.toAscii().constData());
        filepath = QFileDialog::getOpenFileName(NULL, QObject::tr("Open Image"), ".",
                                                QObject::tr("Image Files(*.jpg *.png)"));
        filelist = filepath.split("/");
        filelist.removeLast ();
        folderpath = filelist.join("/");//打开图片所在的文件夹路径
        setpixmap(filepath);
        Open_File(folderpath);//遍历文件夹下边的图片类型文件
    }
    void csImageScan::Open_File(QString path)//遍历文件夹下边的图片类型文件
    {
        QDirIterator m_DirIterator(path,QDir::Files|QDir::NoSymLinks);
        while (m_DirIterator.hasNext())
        {
            QString tempFile=m_DirIterator.next();
            QStringList list=tempFile.split(".");
            //list.takeFirst();
            //QString expandedName=list.takeFirst();
            QString expandedName=list.takeLast();
            if(expandedName=="jpg"||expandedName=="JPG"||expandedName=="png"||expandedName=="PNG"||expandedName=="bmp"||expandedName=="BMP")
            stringlist<<tempFile;
        }
        getposition(stringlist);//获得打开图片在stringlist中的位置
    }
    //获得打开图片在stringlist中的位置
    void csImageScan::getposition(QStringList imagelist)
    {
        //num=0;
        QListIterator<QString> it(imagelist);
        while(it.hasNext())
        {
            if(filepath == it.next())
                break;
            else
                position++;
        }
    }
    //上一张图片
    void csImageScan::on_pre_clicked()
    {
        left=0;
        right=0;
        num_Roll = 0;
        if(0 == stringlist.size())
        {
            printf("get pre image erron \n");
            return ;
        }
        position--;
        if(position<0)
        {
            position=stringlist.size()-1;
        }
        filepath = stringlist.at(position);
        setpixmap(filepath);
    }
    //下一张图片
    void csImageScan::on_next_clicked()
    {
        left=0;
        right=0;
        num_Roll = 0;
        if(0 == stringlist.size())
        {
            printf("get next image erron \n");
            return ;
        }
        position++;
        if(position>stringlist.size()-1)
        {
            position=0;
        }
        filepath = stringlist.at(position);
        setpixmap(filepath);
    }
    //逆时针旋转
    void csImageScan::on_rotuteleft_clicked()
    {
        if(0 == stringlist.size())
        {
            printf("get next image erron \n");
            return ;
        }
        left=1;
        if(left==1&&right==1)
        {
            num_Roll--;
            QMatrix matrix;
            matrix.rotate(-90.0);
            image = image.transformed(matrix,Qt::FastTransformation);
            pix = pix.fromImage(image);
            update();
        }
        else
        {
        num_Roll++;
        image.load(stringlist.at(position));
        QMatrix matrix;
        matrix.rotate(-90.0*num_Roll);
        image = image.transformed(matrix,Qt::FastTransformation);
        pix = pix.fromImage(image);
        update();
        }
    }
    //顺时针旋转
    void csImageScan::on_rotuteright_clicked()
    {
        if(0 == stringlist.size())
        {
            printf("get next image erron \n");
            return ;
        }
        right=1;
        if(left==1&&right==1)
        {
            QMatrix matrix;
            matrix.rotate(90.0);
            image = image.transformed(matrix,Qt::FastTransformation);
            pix = pix.fromImage(image);
            update();
        }
        else
        {
        num_Roll++; 
        image.load(stringlist.at(position));
        QMatrix matrix;
        matrix.rotate(90.0*num_Roll);
        image = image.transformed(matrix,Qt::FastTransformation);
        pix = pix.fromImage(image);
        update();
        }
    }
    //删除图片
    void csImageScan::on_pbdelete_clicked()
    {
        if(stringlist.size() == 0)
            return;
        QMessageBox::StandardButton rb = QMessageBox::question(NULL,"Warning",
                     "Do you want to delete the picture?",QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
        if(rb == QMessageBox::Yes)
        {
            stringlist.takeAt(position);
            QDir dir(folderpath);
            QFileInfoList fileList;
            QFileInfo curFile;
            QStringList filters;
            filters << "*.jpg"<<"*.png";
            fileList=dir.entryInfoList(filters,QDir::Dirs|QDir::Files
                         |QDir::Readable|QDir::Writable
                         |QDir::Hidden|QDir::NoDotAndDotDot
                         ,QDir::Name);
            if(fileList.size()>0)
            {
                curFile=fileList[position];
                QFile fileTemp(curFile.filePath());
                fileTemp.remove();
                fileList.removeAt(position);
            }
            if(0 == stringlist.size())
            {
                printf("get next image erron \n");
                return ;
            }
            filepath = stringlist.at(position);//删除图片以后每张图片的位置就会自动减一,所以仍然加载这个位置的图片就是删除图片的下一张图片
            setpixmap(filepath);
        }
    }
    //重绘事件
    void csImageScan::paintEvent ( QPaintEvent * )
    {
        QPainter painter(this);
        painter.drawPixmap(20,20,pix);
    }
    //加载图片
    void csImageScan::setpixmap(QString imageName)
    {
        pix.load(imageName);
        update();
    }

     csimagescan.h

    #ifndef CSIMAGESCAN_H

    #define CSIMAGESCAN_H
    #include <QDialog>
    #include <QtGui>
    namespace Ui {
        class csImageScan;
    }
    class csImageScan : public QDialog
    {
        Q_OBJECT
    public:
        explicit csImageScan(QWidget *parent = 0);
        ~csImageScan();
    public:
        QString         filepath;//打开图片的路径
        QString         folderpath;
        QStringList     filelist;
        QStringList     stringlist;
        QImage          image;
        QPixmap         pix;
        int             position;//图片在文件夹中的位置
        int             num_Roll;//旋转次数,通过旋转次数来得到旋转角度
        bool            left;
        bool            right;
    private:
        Ui::csImageScan *ui;
    public:
        void paintEvent (QPaintEvent * );
        void setpixmap(QString );
        void Open_File(QString);
        void getposition(QStringList);
    private slots:
        void on_pbdelete_clicked();
        void on_rotuteright_clicked();
        void on_rotuteleft_clicked();
        void on_next_clicked();
        void on_pre_clicked();
        void on_open_clicked();
    };
    #endif // CSIMAGESCAN_H

     

    csimagescan.cpp

    #include "csimagescan.h"

    #include "ui_csimagescan.h"
    csImageScan::csImageScan(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::csImageScan)
    {
        ui->setupUi(this);
        position =0;
        left=0;
        right=0;
        num_Roll = 0;
        //为前后翻转按钮,顺时针逆时针旋转按钮和删除按钮添加图标
        QPixmap m_pixmap("image/pre.png");//前翻转
        QIcon m_icon;
        m_icon.addPixmap(m_pixmap);
        ui->pre->setIcon(m_icon);
        ui->pre->setIconSize(QSize(60,60));
        m_pixmap.load("image/next.png");//后翻转
        m_icon.addPixmap(m_pixmap);
        ui->next->setIcon(m_icon);
        ui->next->setIconSize(QSize(60,60));
        m_pixmap.load("image/left.png");//逆时针
        m_icon.addPixmap(m_pixmap);
        ui->rotuteleft->setIcon(m_icon);
        ui->rotuteleft->setIconSize(QSize(60,60));
        m_pixmap.load("image/right.png");//顺时针
        m_icon.addPixmap(m_pixmap);
        ui->rotuteright->setIcon(m_icon);
        ui->rotuteright->setIconSize(QSize(60,60));
        m_pixmap.load("image/imgdelete.png");//删除
        m_icon.addPixmap(m_pixmap);
        ui->pbdelete->setIcon(m_icon);
        ui->pbdelete->setIconSize(QSize(60,60));
    }
    csImageScan::~csImageScan()
    {
        delete ui;
    }
    void csImageScan::on_open_clicked()//打开对话框选择图片
    {
        position =0;
        stringlist.clear();
        //   printf("%s\n",filepath.toAscii().constData());
        filepath = QFileDialog::getOpenFileName(NULL, QObject::tr("Open Image"), ".",
                                                QObject::tr("Image Files(*.jpg *.png)"));
        filelist = filepath.split("/");
        filelist.removeLast ();
        folderpath = filelist.join("/");//打开图片所在的文件夹路径
        setpixmap(filepath);
        Open_File(folderpath);//遍历文件夹下边的图片类型文件
    }
    void csImageScan::Open_File(QString path)//遍历文件夹下边的图片类型文件
    {
        QDirIterator m_DirIterator(path,QDir::Files|QDir::NoSymLinks);
        while (m_DirIterator.hasNext())
        {
            QString tempFile=m_DirIterator.next();
            QStringList list=tempFile.split(".");
            //list.takeFirst();
            //QString expandedName=list.takeFirst();
            QString expandedName=list.takeLast();
            if(expandedName=="jpg"||expandedName=="JPG"||expandedName=="png"||expandedName=="PNG"||expandedName=="bmp"||expandedName=="BMP")
            stringlist<<tempFile;
        }
        getposition(stringlist);//获得打开图片在stringlist中的位置
    }
    //获得打开图片在stringlist中的位置
    void csImageScan::getposition(QStringList imagelist)
    {
        //num=0;
        QListIterator<QString> it(imagelist);
        while(it.hasNext())
        {
            if(filepath == it.next())
                break;
            else
                position++;
        }
    }
    //上一张图片
    void csImageScan::on_pre_clicked()
    {
        left=0;
        right=0;
        num_Roll = 0;
        if(0 == stringlist.size())
        {
            printf("get pre image erron \n");
            return ;
        }
        position--;
        if(position<0)
        {
            position=stringlist.size()-1;
        }
        filepath = stringlist.at(position);
        setpixmap(filepath);
    }
    //下一张图片
    void csImageScan::on_next_clicked()
    {
        left=0;
        right=0;
        num_Roll = 0;
        if(0 == stringlist.size())
        {
            printf("get next image erron \n");
            return ;
        }
        position++;
        if(position>stringlist.size()-1)
        {
            position=0;
        }
        filepath = stringlist.at(position);
        setpixmap(filepath);
    }
    //逆时针旋转
    void csImageScan::on_rotuteleft_clicked()
    {
        if(0 == stringlist.size())
        {
            printf("get next image erron \n");
            return ;
        }
        left=1;
        if(left==1&&right==1)
        {
            num_Roll--;
            QMatrix matrix;
            matrix.rotate(-90.0);
            image = image.transformed(matrix,Qt::FastTransformation);
            pix = pix.fromImage(image);
            update();
        }
        else
        {
        num_Roll++;
        image.load(stringlist.at(position));
        QMatrix matrix;
        matrix.rotate(-90.0*num_Roll);
        image = image.transformed(matrix,Qt::FastTransformation);
        pix = pix.fromImage(image);
        update();
        }
    }
    //顺时针旋转
    void csImageScan::on_rotuteright_clicked()
    {
        if(0 == stringlist.size())
        {
            printf("get next image erron \n");
            return ;
        }
        right=1;
        if(left==1&&right==1)
        {
            QMatrix matrix;
            matrix.rotate(90.0);
            image = image.transformed(matrix,Qt::FastTransformation);
            pix = pix.fromImage(image);
            update();
        }
        else
        {
        num_Roll++; 
        image.load(stringlist.at(position));
        QMatrix matrix;
        matrix.rotate(90.0*num_Roll);
        image = image.transformed(matrix,Qt::FastTransformation);
        pix = pix.fromImage(image);
        update();
        }
    }
    //删除图片
    void csImageScan::on_pbdelete_clicked()
    {
        if(stringlist.size() == 0)
            return;
        QMessageBox::StandardButton rb = QMessageBox::question(NULL,"Warning",
                     "Do you want to delete the picture?",QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
        if(rb == QMessageBox::Yes)
        {
            stringlist.takeAt(position);
            QDir dir(folderpath);
            QFileInfoList fileList;
            QFileInfo curFile;
            QStringList filters;
            filters << "*.jpg"<<"*.png";
            fileList=dir.entryInfoList(filters,QDir::Dirs|QDir::Files
                         |QDir::Readable|QDir::Writable
                         |QDir::Hidden|QDir::NoDotAndDotDot
                         ,QDir::Name);
            if(fileList.size()>0)
            {
                curFile=fileList[position];
                QFile fileTemp(curFile.filePath());
                fileTemp.remove();
                fileList.removeAt(position);
            }
            if(0 == stringlist.size())
            {
                printf("get next image erron \n");
                return ;
            }
            filepath = stringlist.at(position);//删除图片以后每张图片的位置就会自动减一,所以仍然加载这个位置的图片就是删除图片的下一张图片
            setpixmap(filepath);
        }
    }
    //重绘事件
    void csImageScan::paintEvent ( QPaintEvent * )
    {
        QPainter painter(this);
        painter.drawPixmap(20,20,pix);
    }
    //加载图片
    void csImageScan::setpixmap(QString imageName)
    {
        pix.load(imageName);
        update();
    }
     
    
     
    

     

    展开全文
  • Qt下的图片浏览器

    2014-07-12 18:32:26
    Qt 图片浏览器 沈阳工程学院 mini2440 linux课设 课设高分作品,无需修改,直接=最后答辩,轻松2周。
  • 基于QT图片浏览器

    2019-06-06 11:31:50
    基于QT图片浏览器,支持左右翻页,拉伸填充,逐渐显示,按键移动等功能
  • 基于qt4.7图片浏览器

    2012-10-09 15:28:40
    基于qt4.7标准的图片浏览器
  • QT4实现图片浏览器

    2012-06-04 17:17:34
    QT4实现图片浏览器,希望大家喜欢。很好的例子,原创
  • qt实现windows上的图片浏览器,并进行了功能改进。在原有的基础上,增加了添加照片和删除照片的功能。适合用于熟悉qt的一个非常好的例子。
  • qt做的图片浏览器

    2015-04-12 22:38:59
    qt做的图片浏览器,使用的环境是vs2013,估计兼容不了Mingw。代码简单, 自己建一个qt gui项目拷入代码即可
  • 在linx下QT4图片浏览器

    2011-01-14 15:00:10
    在LINUX+QT4下写的一个图片浏览器,先用designer设计框架
  • Qt 图片漫画浏览器

    2011-04-12 18:38:31
    基于Nokia N8 5320等手机开发的漫画浏览器,包含多界面的切换,大小图查看,手势滑动等,供大家参考之用
  • 实用Qt编写的图片浏览器的程序,非常容易移植到各种嵌入式开发平台。代码简洁容易上手。
  • 基于Qt4图片浏览器,有源代码,多多交流学习
  • 利用QT实现的和Windwos图片浏览器一样的效果,有完整的代码注释。开发环境QT5.2。在Lab中显示的是坐标的参数,可以忽略。
  • Qt实现图片浏览器源代码(简单实例)。。。。。。。。。。。。。。。。

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 6,777
精华内容 2,710
关键字:

qt图片浏览器