Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QScrollArea not expanding when QPixmap is loaded

    General and Desktop
    qscrollarea qpixmap qlabel
    3
    3
    271
    Loading More Posts
    • 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
      Conical last edited by Conical

      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.

      raven-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @Conical last edited by

        @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 Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          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 Reply Quote 0
          • First post
            Last post