There is a QTabWidget . In its tab you need to add a widget, for example QLabel . The tab is just a widget, inside of which is a QHBoxLayout , and inside it is a Scroll Bar and Spacer.

 QWidget* tab = ui->tabs->widget(0); QLabel* lbl = new QLabel(tab); QFont font; font.setPixelSize(24); lbl->setFont(font); lbl->setText("Some Text"); tab->layout()->addWidget(lbl); 

In theory, the last line is tab->layout()->addWidget(lbl); It just adds the same QLabel left of the tab, but it inserts the text outside the layout'a from the bottom (because there is a vertical layout.

Please explain what the problem is and how to fix it.

Tab Conclusion

  • Here is this widget (not QTabWidget itself, namely the tab) in your designer is made? Give a screen hierarchy then. Or, if the tab is created dynamically, then the code. - alexis031182
  • @ alexis031182 yes, in the designer. And what is the best? Code in the constructor? - sm4ll_3gg
  • Not that it is better, but when one is like that and the other is like that, it is probably not very convenient. Since there is a need for the dynamics of a part of the widget, then it probably makes sense to create all of it not in the designer. But this is the lyrics. And in fact, the problems are: externally, it seems, everything is correct, but since this is not true in fact, check in the properties that the horizontal layout may not be assigned to the widget tab. Although, here you can see on the screen that the parent connection is exactly there. - alexis031182
  • @ alexis031182 added an output screen, all evening yesterday I tried to figure it out, but everything seems to be so. Passed by debager and by the layout() method, it adequately returns a pointer to it - sm4ll_3gg
  • It seems that the designer is making a garden of two layouts instead of one. Try in the code, where you get a pointer to the layout, to search for a child object. For example: QHBoxLayout *hlayout = tab->layout()->findChild<QHBoxLayout*>() . Well, see if the pointer will be zero or will it still find the hidden layer. - alexis031182

1 answer 1

The problem was in the forms compiled in QtDesigner . Perepesil form hands and everything began to work normally.

  • So so the answer ... - Qwertiy
  • @Qwertiy as it is. I have no idea why this happens in the designer. Maybe someone knows, there are 2 days - sm4ll_3gg
  • And compare files? - Qwertiy
  • @Qwertiy I suspect that this is due to the layout on the forms, that it is considered a separate layout'om. But I am not sure, but there is no time to check it now - sm4ll_3gg