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. Resizing problems with widgets
Forum Updated to NodeBB v4.3 + New Features

Resizing problems with widgets

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 8.5k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    sigipa
    wrote on last edited by
    #1

    Hello All,

    I'm having some problems with widget resizing in my app. I have a QScrollArea and a QWidget with a QVBoxLayout. I am adding multiple QLabel widgets with pixmaps to the layout. The problem is when I resize the QScrollArea, all of the other widgets including the pixmaps are being resized. When I resize the labels and update the QVBoxLayout, everything gets resized to fit the QScrollArea. The behavior I need is for the QScrollArea to adjust it's scrollbars to fit the children and for the QVBoxLayout to layout based on the child widgets size instead of the QScrollArea size. I hope that makes sense. I've been digging through the docs, but I guess I may be missing something in understanding how sizing works. I could really use some advice on this. Could one of y'all point me in the right direction?

    Thanks,
    -S

    1 Reply Last reply
    0
    • E Offline
      E Offline
      evergreen
      wrote on last edited by
      #2

      I had the same problem some times ago. You have to make the QScrollArea get only one widget.

      Here's the whole method I used :

      -Put all you need in a general layout
      -Set the parent of that layout as a general widget
      -Use void QScrollArea::setWidget ( QWidget * widget )

      The behaviour of the scroll area should be allright

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sigipa
        wrote on last edited by
        #3

        Hi,

        Thanks for your help! I think I am already doing this. Here my code (the latest version anyway):

        @

        ...

        vlayout = new QVBoxLayout();

        vlayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
        scrollArea = new QScrollArea;
        scrollArea->setBackgroundRole(QPalette::Dark);
        scrollArea->setWidgetResizable(true);
        scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);

        baseWidget = new QWidget(scrollArea);
        baseWidget->setMinimumSize(100,100);
        baseWidget->setMaximumSize(2000, 11000);

        baseWidget->setLayout(vlayout);

        scrollArea->setWidget(baseWidget);
        setCentralWidget(scrollArea);

        ...

        for (index = 1; index <= pagecnt; index++)
        {

        ...

        QImage image((const uchar *)bits, hdr.width, hdr.height, QImage::Format_RGB888);

        QLabel *label = new QLabel(baseWidget);
        label->setBackgroundRole(QPalette::Base);
        label->setScaledContents(true);

        label->setPixmap(QPixmap::fromImage(image));
        label->resize(label->pixmap()->size());
        vlayout->addWidget(label);
        }

        @

        Everything displays correctly initially. When I resize the main window, the children of the scroll area resize. When I resize the labels, the scroll area's scroll bars do not update to the new size. If I resize the labels and then change the main window size, the labels are resized to the scroll area size. Is there something that I'm missing?

        Thanks,
        -G

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sigipa
          wrote on last edited by
          #4

          Hello All,

          I figured this out. I need to call label->setMinimumSize and label->setMaximumSize.

          Thanks,
          -G

          1 Reply Last reply
          0

          • Login

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