Results 1 to 2 of 2

Thread: Problem regardin QScrollArea and iimage inside - Please help

  1. #1
    Join Date
    Nov 2009
    Posts
    29
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Problem regardin QScrollArea and iimage inside - Please help

    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.

  2. #2
    Join Date
    Nov 2009
    Posts
    29
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Please Help! - QScrollArea and QLabel image resize

    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

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit MainWindow(QWidget *parent = 0);
    16. ~MainWindow();
    17.  
    18. private slots:
    19. void zoom();
    20.  
    21. private:
    22. Ui::MainWindow *ui;
    23. };
    24.  
    25. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    and mainwindow.cpp

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QImage>
    4.  
    5. MainWindow::MainWindow(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::MainWindow)
    8. {
    9. ui->setupUi(this);
    10.  
    11. QImage img("C:/Qt/Programas/PruebaScrollArea/Desert.jpg");
    12.  
    13. ui->label->setPixmap(QPixmap::fromImage(img));
    14.  
    15. connect(ui->actionZoom, SIGNAL(triggered()), this, SLOT(zoom()));
    16. }
    17.  
    18. MainWindow::~MainWindow()
    19. {
    20. delete ui;
    21. }
    22.  
    23. void MainWindow::zoom()
    24. {
    25. ui->label->resize(ui->label->pixmap()->size()*2.0);
    26. }
    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.

Similar Threads

  1. Ho do I Expand QGrpahicsView off screen inside a QScrollArea?
    By hybrid_snyper in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2013, 22:21
  2. Replies: 0
    Last Post: 16th July 2012, 10:56
  3. QwtPlot inside QScrollArea
    By mastupristi in forum Qwt
    Replies: 3
    Last Post: 13th October 2009, 05:28
  4. resizing widget inside QScrollArea
    By mastupristi in forum Newbie
    Replies: 4
    Last Post: 16th July 2009, 20:29
  5. QScrollArea problem positioning a QWidget inside
    By Spectator in forum Qt Programming
    Replies: 4
    Last Post: 20th February 2006, 23:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.