qtsmartgraphics  2.1.1
A simple library that improves the user experience when displaying images by Qt's QLabel and QGraphicsView.
Usage

The tutorial shows how to use the widget.

Interface

This is the sample of the QSmartGraphicsView. The left view receives the image loaded from the system, and the right view receives the selected sub-image of the left view.

Imgur

The left top corner of any view is the menu bar. The eye is normal view mode, and the arrow is the region selection mode.

Imgur

The menu bar can be hidden by pressing the key 'H' on your keyboard,

Imgur

or right click on the view to hide it.

Imgur

In region selection mode, you have to press Ctrl to drag the image around. Feel free to select any region then right click

Imgur

and press "Copy Selected Region" to get the sub-image.

Imgur

Code

The following code reads the image from the system and puts into the qsmartgraphicsview

1 QStringList fileNames = QFileDialog::getOpenFileNames(this,tr("Open File"),0,"Image files (*.png *.bmp *.jpg);;PNG (*.png);;BMP (*.bmp);;JPG (*.jpg)");
2 
3 if(fileNames.isEmpty())
4  return;
5 
6 int img_w = 0, img_h = 0;
7 std::vector<QImage> images;
8 for(int i = 0; i < fileNames.size(); i++)
9 {
10  QImage tmp(fileNames.at(i));
11  if(!tmp.isNull())
12  {
13  if(tmp.width() > img_w){img_w = tmp.width();}
14  if(tmp.height() > img_h){img_h = tmp.height();}
15  images.push_back(tmp);
16  }
17 }
18 
19 if(!images.empty())
20 {
21  ui->graphicsView->initialize(images.size(), img_w, img_h); //initial qgraphics view
22  ui->graphicsView->setImagefromQImage(images);
23 }

qsmartgraphicsview must be initialize before use.

The "Copy Selected Region" function triggers a signal sendSelectedRegion(QImage) when clicked. You can connect it to a slot to receive the image.

1 MainWindow::MainWindow(QWidget *parent) :
2  QMainWindow(parent),
3  ui(new Ui::MainWindow)
4 {
5  ui->setupUi(this);
6  connect(ui->graphicsView, SIGNAL(sendSelectedRegion(QImage)),this,SLOT(receiveSelectedRegion(QImage)));
7 }
8 
9 void MainWindow::receiveSelectedRegion(const QImage &img)
10 {
11  //Do something
12 }