Hello everyone,
I am having a lot of trouble with this, please help me.
I am following the Image Viewer example, but I am using Designer.
I have a MainWindow, inside a QScrollArea and inside a QLabel to show an image.
My GUI looks like this:
Screen1.jpg
And I have a zoom action.
My files are:
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private slots:
void zoom();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void zoom();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
and mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QImage>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
QImage img
("C:/Qt/Programas/PruebaScrollArea/Desert.jpg");
ui
->label
->setPixmap
(QPixmap::fromImage(img
));
connect(ui->actionZoom, SIGNAL(triggered()), this, SLOT(zoom()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::zoom()
{
ui->label->resize(ui->label->pixmap()->size()*2.0);
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QImage>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QImage img("C:/Qt/Programas/PruebaScrollArea/Desert.jpg");
ui->label->setPixmap(QPixmap::fromImage(img));
connect(ui->actionZoom, SIGNAL(triggered()), this, SLOT(zoom()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::zoom()
{
ui->label->resize(ui->label->pixmap()->size()*2.0);
}
To copy to clipboard, switch view to plain text mode
When I run the program, the image show fine, with the scrollbars correctly like the following image:
Screen2.jpg
When I maximize, the image shows like this, with the scrollbars correctly disabled:
Screen3.jpg
But when I zoom to double the image size, the image seems to move and nothing happens to the scrollbars:
Screen4.jpg
What is happening there? I´been struggling with this and I don´t know why it doesn´t work well.
In scrollarea I have widgerResizable to true and in label I have the scaleContents false.
I´ll appreciate your help.
Bookmarks