PDA

View Full Version : Problem regardin QScrollArea and iimage inside - Please help



rdelgado
5th September 2014, 16:54
Hello,

I am trying to find some guidance using QScrollArea.

I am following de Image Viewer example, but I am using Designer to make the GUI.
I have a QScrollArea and some buttons.

Inside the QScrollArea I set a Layout, and then i put a QLabel to use as imageLabel.

Then I follow the code in the Image Viewer example and everything works fine. I can display the image, and I can zoom in and out, but my problem is the following:
When I zoom out or in, the QScrollArea seem to keep the layout inside it always the same size as the original image size. So, when I zoom out the image rescales correctly, but the QScrollBars dont update its size, and when I scroll up or down, left or right, I can see white space where the bigger image used to be.
The problem I seem to have is that the layout inside the QScrollArea seems to be keeping its size, event when I set its property to preferred in Designer.

Do you have any idea what can be the problem?

Thank you very much!

P.S.: Excuse my english.

rdelgado
5th September 2014, 19:41
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:

10618

And I have a zoom action.

My files are:

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

and mainwindow.cpp


#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);
}


When I run the program, the image show fine, with the scrollbars correctly like the following image:

10619

When I maximize, the image shows like this, with the scrollbars correctly disabled:

10620

But when I zoom to double the image size, the image seems to move and nothing happens to the scrollbars:

10621

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.