Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QScrollArea not expanding when QPixmap is loaded
QtWS25 Last Chance

QScrollArea not expanding when QPixmap is loaded

Scheduled Pinned Locked Moved Unsolved General and Desktop
qscrollareaqpixmapqlabel
3 Posts 3 Posters 675 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Conical
    wrote on 24 Mar 2020, 15:34 last edited by Conical
    #1

    Hi all,

    I'm working on a program that requires the user to load an image. I am using a QPixmap inside of a QLabel for the image, and that QLabel is inside a QScrollArea. When the program first starts, the label is empty, and thus the scroll area doesn't have anywhere to scroll (as intended). However, when I load an image that requires scrolling, the scroll bars do not change, and I can only see the top corner of the image.

    Currently, this is the code that sets the image in the QLabel (the image paths are stored in a list):

    void MainWindow::on_imageList_doubleClicked(const QModelIndex &index)
    {
        QPixmap image(imageModel->itemData(index)[0].toString());
        ui->imagePanel->setPixmap(image);
    }
    

    As I said earlier, the QLabel (imagePanel) is inside the scroll area, so I am confused as to why the scroll bars do not expand to accommodate a large image.

    Any helps would be much appreciated.

    Edit: I admit that my explanation is a little confusing, so here's a screenshot showing what I mean. The picture is supposed to be scrollable so you can view the entire cat, but only a small part of the picture can be seen and the scroll bars do not work.
    Screenshot_2020-03-24_15-39-17.png
    I can somewhat get around the issue by setting the QLabel scaledContents to true, but it's not ideal as the height/width ratio is not maintained.

    R 1 Reply Last reply 24 Mar 2020, 17:46
    0
    • C Conical
      24 Mar 2020, 15:34

      Hi all,

      I'm working on a program that requires the user to load an image. I am using a QPixmap inside of a QLabel for the image, and that QLabel is inside a QScrollArea. When the program first starts, the label is empty, and thus the scroll area doesn't have anywhere to scroll (as intended). However, when I load an image that requires scrolling, the scroll bars do not change, and I can only see the top corner of the image.

      Currently, this is the code that sets the image in the QLabel (the image paths are stored in a list):

      void MainWindow::on_imageList_doubleClicked(const QModelIndex &index)
      {
          QPixmap image(imageModel->itemData(index)[0].toString());
          ui->imagePanel->setPixmap(image);
      }
      

      As I said earlier, the QLabel (imagePanel) is inside the scroll area, so I am confused as to why the scroll bars do not expand to accommodate a large image.

      Any helps would be much appreciated.

      Edit: I admit that my explanation is a little confusing, so here's a screenshot showing what I mean. The picture is supposed to be scrollable so you can view the entire cat, but only a small part of the picture can be seen and the scroll bars do not work.
      Screenshot_2020-03-24_15-39-17.png
      I can somewhat get around the issue by setting the QLabel scaledContents to true, but it's not ideal as the height/width ratio is not maintained.

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 24 Mar 2020, 17:46 last edited by
      #2

      @Conical
      you need to resize the QLabel in the scrollarea to the size of the pixmap

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 24 Mar 2020, 19:04 last edited by
        #3

        Hi,

        How did you set the QLabel on your QScrollArea ?

        If you put it in a layout on the scroll area then that's wrong.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        3/3

        24 Mar 2020, 19:04

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved