0

So i Have a QVBoxLayout with two child layouts. The first one has labels inside it, and the second one consists of glwidget. The goal is to make first layout the exact size needed to show the labels, not larger, not smaller (widgets are aligned to the top). (So it actually takes a small part of the screen). And i need it to be independent of the window size. I tried some stuff and currently i'm just using addStrech to make it at least passable. So i Was wondering. Could i achieve what i want by the means of layouts management?

  QVBoxLayout *v_layout = new QVBoxLayout (this);

  QHBoxLayout *labels_layout = new QHBoxLayout (this);
  QVBoxLayout *labels_layout1 = new QVBoxLayout (this);
  QVBoxLayout *labels_layout2 = new QVBoxLayout (this);

  QVBoxLayout *drawer_layout = new QVBoxLayout (this);

  number_of_points_label = new QLabel (this);
  set_n_label ();

  function_name_label = new QLabel (this);
  set_func_label ();

  state_label = new QLabel (this);
  set_state_label ();

  fabs_max_label = new QLabel (this);
  change_fabs_max_label ();

  drawer_layout->addWidget (drawer);

  labels_layout->setAlignment (Qt::AlignTop);
  labels_layout1->addWidget (number_of_points_label);
  labels_layout1->addWidget (function_name_label);
  labels_layout1->addWidget (fabs_max_label);
  labels_layout2->addWidget (state_label);

  labels_layout->addLayout (labels_layout1);
  labels_layout->addLayout (labels_layout2);

  v_layout->addLayout (labels_layout);
  v_layout->addLayout (drawer_layout);


  v_layout->setStretchFactor (labels_layout, 1);
  v_layout->setStretchFactor (drawer_layout, 8);
vowchick
  • 11
  • 4
  • 1
    You probably have to show a diagram and your minimal code to get help. – drescherjm Sep 04 '20 at 16:52
  • Just a guess but rather than adding a stretch try setting the [stretch factor](https://doc.qt.io/qt-5/qboxlayout.html#addWidget) when you add the glwidget. – G.M. Sep 04 '20 at 17:04
  • Added the needed code. I meant setStrechFactor of course – vowchick Sep 04 '20 at 18:55
  • Something like this? [SO: How do I rotate my camera correctly in my 3D world?](https://stackoverflow.com/a/60576857/7478597) ;-) – Scheff's Cat Sep 05 '20 at 09:50
  • Please, try `v_layout->setStretchFactor(labels_layout, 0);` and `v_layout->setStretchFactor(drawer_layout, 1);` (or just use the 2nd parameter of `addLayout()` for this). This tells the layout to provide all left space to `drawer_layout` while `label_layout` has to consume just as much as necessary. – Scheff's Cat Sep 05 '20 at 09:56

0 Answers0