It will help you to put a lot of pictures in one scrolling, and will be stabilized by their size.
.h file
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class QLabel;
class QScrollArea;
class FlowLayout;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
void setImagePaths(const QStringList& paths);
private:
QScrollArea* m_area;
QVector <QLabel*> m_imagesLab;
FlowLayout *flowLayout;
};
#endif // MAINWINDOW_H
.cpp file
#include "mainwindow.h"
#include "flowlayout.h"
#include <QScrollArea>
#include <QLabel>
#include <QVBoxLayout>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
m_area = new QScrollArea(this);
m_area->setWidgetResizable(true);
flowLayout = new FlowLayout;
QWidget* widget = new QWidget(this);
widget->setLayout(flowLayout);
m_area->setWidget(widget);
setCentralWidget(m_area);
}
void MainWindow::setImagePaths(const QStringList &paths)
{
foreach (QString path, paths) {
QLabel* lab = new QLabel(this);
lab->setPixmap(path);
flowLayout->addWidget(lab);
m_imagesLab.push_back(lab);
}
}
MainWindow::~MainWindow()
{
}
flowlayout.h
and flowlayout.cpp
you can find in QT example,
Flow Layout
Example Shows how to arrange widgets for different window
sizes.
Flow Layout implements a layout that handles different window sizes.
The widget placement changes depending on the width of the application
window.
QTextBrowser
for this task. – Vahagn Avagyan