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. trouble with height-for-width

trouble with height-for-width

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 300 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.
  • D Offline
    D Offline
    django.Reinhard
    wrote on last edited by django.Reinhard
    #1

    Hi,

    I'm playing with flowlayout-example and added some dialog-like widgets of constant size.
    This is a screenshot of all children in a big-enuf container:
    Flow_allChildren.png

    ... but I don't have that plenty space in my app, so real app-window looks like this:
    Flow_realSize.png
    Layout works as expected, but elements outside of visible container can't be accessed.

    So I added a QScrollArea, which leads to this picture:
    Flow_wrongLayout.png
    Now layout does not calculate any other possible width, as the smallest width could be made high enuf for all children.

    I don't want to limit height of scrollarea - number of children and (constant) size is variable. So I'm looking for a way to change layout so that first the width is occupied, before wrapping happens.

    I guess to achieve that, I have to overload some internal Qt classes. If anybody has done something similar, a helping hand is appreciated!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are you applying the layout on the QScrollArea itself or on a widget that you set on the QScrollArea ?

      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
      • D Offline
        D Offline
        django.Reinhard
        wrote on last edited by
        #3

        Hi,

        I was puzzled by your question. I was about to write "of course I assigned the layout to the widget that was included in the scrollarea ...", but then I thought: Hey, why not ...
        ... and tried it out: Unfortunately, after adding the layout, the ScrollArea was no longer a ScrollArea. At least there were no scrollbars and the ContentArea was also fixed.

        Now I don't know what to do. Should I assign the layout to the ScrollArea and research why there are no scrollbars anymore, or was the first way more correct?

        In between I thought maybe I could use the resize event to make the layout recalculate from the top, but after a resize event so much goes off internally that I have no plan what I need from it, or how to get my layout to act only on my request.

        JonBJ 1 Reply Last reply
        0
        • D django.Reinhard

          Hi,

          I was puzzled by your question. I was about to write "of course I assigned the layout to the widget that was included in the scrollarea ...", but then I thought: Hey, why not ...
          ... and tried it out: Unfortunately, after adding the layout, the ScrollArea was no longer a ScrollArea. At least there were no scrollbars and the ContentArea was also fixed.

          Now I don't know what to do. Should I assign the layout to the ScrollArea and research why there are no scrollbars anymore, or was the first way more correct?

          In between I thought maybe I could use the resize event to make the layout recalculate from the top, but after a resize event so much goes off internally that I have no plan what I need from it, or how to get my layout to act only on my request.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @django-Reinhard
          @SGaist was just verifying that you did indeed assign layout to widget, not to scroll area. This is correct way.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            django.Reinhard
            wrote on last edited by
            #5

            Hi,

            just to close this:

            I compiled a Qt with debug info and debugged the layout process. Then I thought, I should extend QLayout::totalSizeHint() - but that function is not virtual. So patching Qt would become expensive :(

            So I thought, may be QScrollArea has a property for preferred extend direction - which is not the case.
            But on that research I discovered QScrollArea::setWidgetResizable() ...

            Oh happy day! That did the trick :)

            I have nothing to extend or patch, just use this property.
            What a revelation :D

            Finally my code looks something like this:

            Window::Window()
             : client(new QWidget(this)) {
              FlowLayout*  fl = new FlowLayout;
              QScrollArea* sa = new QScrollArea;
            
              setLayout(new QVBoxLayout);
              layout()->setMargin(0);
              client->setLayout(fl);  
              fl->setMargin(0);
            
              fl->addWidget(...);
              fl->addWidget(...);
              ...
            
              sa->setWidget(client);
              sa->setWidgetResizable(true);
              layout()->addWidget(sa);
              }
            

            ... and the result looks like:
            Flowlayout_resized.png

            Yeah!

            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