• 大小: 21KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: 其他
  • 标签: qt  图片  

资源简介

QtImage Qt编写的图片浏览器 QtImage Qt编写的图片浏览器

资源截图

代码片段和文件信息

#include 
#include 
#include 
#include 
#include “ImageViewer.h“

ImageViewer::ImageViewer(QWidget *parent)
    : QMainWindow(parent) scaleFactor(1)
{
setupUi(this);
imageLabel = new QLabel;
imageLabel->setBackgroundRole(QPalette::base);
imageLabel->setSizePolicy(QSizePolicy::Ignored QSizePolicy::Ignored);
imageLabel->setScaledContents(true);
scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(imageLabel);
setCentralWidget(scrollArea);
dirModel = new QDirModel(this);
dirModel->setFilter(QDir::Dirs | QDir::Drives);
dirCurrent = new QDir();
imageInfo = new QLabel(this);
imageInfo->setSizePolicy(QSizePolicy::ExpandingQSizePolicy::Expanding);
imageInfo->setAlignment(Qt::AlignCenter);
imageInfo->setStatusTip(tr(“Display image infomation in the selected folder“));
toolBar->addWidget(imageInfo);
treeView->setModel(dirModel);
treeView->header()->setVisible(false);
treeView->setColumnHidden(1true); // Size
treeView->setColumnHidden(2true);  // Type
treeView->setColumnHidden(3true);  // Modified Date
foreach (QByteArray ba QImageReader::supportedImageFormats())
{
QString ext = QString(“*.“)+QString(ba);
supportFormat< }
resize(780580);
currentFile = displayFiles.constBegin();
UpdateUI();
}

ImageViewer::~ImageViewer()
{
delete dirCurrent;
}

void adjustScrollBar(QScrollBar *scrollBar double factor)
{
    scrollBar->setValue(int(factor * scrollBar->value()
                            + ((factor - 1) * scrollBar->pageStep()/2)));
}

void ImageViewer::scaleImage(double factor)
{
    Q_ASSERT(imageLabel->pixmap());
    scaleFactor *= factor;
    imageLabel->resize(scaleFactor * imageLabel->pixmap()->size());

    adjustScrollBar(scrollArea->horizontalScrollBar() factor);
    adjustScrollBar(scrollArea->verticalScrollBar() factor);
}

void ImageViewer::DisplayImage(const QString &fileName)
{
QImage image(fileName);
if (image.isNull()) {
    QMessageBox::information(this tr(“Image Viewer“)
                             tr(“Cannot load %1.“).arg(fileName));
    return;
}
imageLabel->setPixmap(QPixmap::fromImage(image));
scaleImage(1.0);
}

void ImageViewer::UpdateUI()
{
if(currentFile == displayFiles.constEnd())
{
imageInfo->setText(tr(“No Images Click TreeView to select pic folder“));
actionNext->setEnabled(false);
actionPrevious->setEnabled(false);
actionZoomIn->setEnabled(false);
actionZoomOut->setEnabled(false);
actionNormalSize->setEnabled(false);
}
else
{
int i = displayFiles.indexOf(*currentFile 0) + 1; // non-Programmer count from 1 instead 0
imageInfo->setText(QString(tr(“%1/%2 %3 %4%“)).arg(i).arg(displayFiles.size()).arg(*currentFile).arg(scaleFactor*100 3));
actionNext->setEnabled(true);
actionPrevious->setEnabled(true);
actionZoomIn->setEnabled(true);
actionZoomOut->

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    .......       934  2006-08-27 16:43  ImageViewer.h

    .......      4691  2006-08-27 22:51  ImageViewer.cpp

    .......       215  2006-08-16 21:30  main.cpp

    .......     53248  2006-08-27 22:53  QtImage.exe

    .......       405  2006-08-17 15:55  QtImage.pro

    .......       296  2006-08-27 03:36  QtImageRes.qrc

    .......      4217  2006-08-27 16:55  ImageViewer.ui

     文件        929  2004-10-13 08:57  images\about.png

     文件        982  2004-10-13 09:02  images\apply.png

     文件        754  2004-10-13 09:31  images\next.png

     文件        703  2004-10-13 09:31  images\previous.png

     文件        877  2004-10-15 08:55  images\zoomin.png

     文件       1107  2004-10-13 08:59  images\zoomnormal.png

     文件        886  2004-10-15 08:54  images\zoomout.png

     目录          0  2006-08-16 21:47  images

----------- ---------  ---------- -----  ----

                70244                    15


评论

共有 条评论