0

I am writing a program to read a number of units consisting of two fields. It has to be graphic, so to store and display all the input fields I use QVBoxLayout and it looks like this: Input fields

In order to avoid all the inconveniences that may occur when the window is resized, I wrote some code to automatically resize this layout so it fills whole window vertically:

void resizeLayout(const int& w, const int& h, QVBoxLayout* box) {
    QRect prevGeom = box->geometry();
    prevGeom.setHeight(h);
    prevGeom.setWidth(w);
    box->setGeometry(prevGeom);
}

And it works relatively fine if not for one thing. When I resize it compresses or hides some input fields like this:That's not right Anybody knows what am I doing wrong here?

  • You may resize the layout, but the in any case all widgets have a `sizeHint` you may refer to it to understand what is happening. Probably they have a min/max `sizeHint`. – Ilian Zapryanov Apr 27 '22 at 16:28
  • 1
    This is not how layouts are supposed to be used. Layouts are designed to adjust their size automatically to available space and to the size hints, stretches, margins, spacings etc. of the widgets contained in them. Btw. why are you using `const int &`? – HiFile.app - best file manager Apr 27 '22 at 18:09
  • I am using const int& because passing arguments by reference is faster than by value, and yeah, I know that here that minute optimization won't do much, but thats just a habit. Thank you for your answer, could you tell me please, how to "tell" the layout what space it has? – saladwithgrass Apr 27 '22 at 19:52
  • The layout has a size hint based on its configuration and the size hints/policies of the various widgets/layouts it manages. This, generally speaking, becomes the size hint of the widget using the layout. That being the case, why do you want to `"tell" the layout what space it has`? What's the *real* problem you're trying to solve? – G.M. Apr 27 '22 at 20:18
  • Re. `"...passing arguments by reference is faster than by value"`, you might want to look at [this post](https://stackoverflow.com/questions/270408/is-it-better-in-c-to-pass-by-value-or-pass-by-constant-reference). – G.M. Apr 27 '22 at 20:23

0 Answers0