• 大小: 1.37M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-04-18
  • 语言: C/C++
  • 标签: 图形  Qt  

资源简介

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->

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-12-27 22:55  QtImage\
     文件        1448  2020-12-27 19:12  QtImage\.qmake.stash
     文件        4691  2006-08-27 22:51  QtImage\ImageViewer.cpp
     文件         934  2006-08-27 16:43  QtImage\ImageViewer.h
     文件        4217  2006-08-27 16:55  QtImage\ImageViewer.ui
     文件       29093  2020-12-27 19:19  QtImage\Makefile
     文件       48244  2020-12-27 19:19  QtImage\Makefile.Debug
     文件       48260  2020-12-27 19:19  QtImage\Makefile.Release
     文件       53248  2006-08-27 22:53  QtImage\QtImage.exe
     文件         469  2020-12-27 19:18  QtImage\QtImage.pro
     文件       24633  2020-12-27 22:55  QtImage\QtImage.pro.user
     文件         296  2006-08-27 03:36  QtImage\QtImageRes.qrc
     目录           0  2020-12-27 19:18  QtImage\debug\
     文件      305601  2020-12-27 19:18  QtImage\debug\ImageViewer.obj
     文件      125440  2020-12-27 19:18  QtImage\debug\QtImage.exe
     文件     1433584  2020-12-27 19:18  QtImage\debug\QtImage.ilk
     文件     2428928  2020-12-27 19:18  QtImage\debug\QtImage.pdb
     文件     1757184  2020-12-27 19:18  QtImage\debug\QtImage.vc.pdb
     文件       99791  2020-12-27 19:18  QtImage\debug\main.obj
     文件        5100  2020-12-27 19:18  QtImage\debug\moc_ImageViewer.cpp
     文件      105991  2020-12-27 19:18  QtImage\debug\moc_ImageViewer.obj
     文件         229  2020-12-27 19:18  QtImage\debug\moc_predefs.h
     文件       31284  2020-12-27 19:18  QtImage\debug\qrc_QtImageRes.cpp
     文件       12166  2020-12-27 19:18  QtImage\debug\qrc_QtImageRes.obj
     目录           0  2010-04-21 02:16  QtImage\images\
     文件         929  2004-10-13 08:57  QtImage\images\about.png
     文件         982  2004-10-13 09:02  QtImage\images\apply.png
     文件         754  2004-10-13 09:31  QtImage\images\next.png
     文件         703  2004-10-13 09:31  QtImage\images\previous.png
     文件         877  2004-10-15 08:55  QtImage\images\zoomin.png
     文件        1107  2004-10-13 08:59  QtImage\images\zoomnormal.png
............此处省略4个文件信息

评论

共有 条评论