简体   繁体   English

Qt :: QStackedWidget插入vs子窗口小部件构造函数调用

[英]Qt::QStackedWidget insert vs child widget constructor call

Using a QStackedWidget, what is the best practice for placing a widget on it? 使用QStackedWidget,在其上放置小部件的最佳实践是什么? should I be calling the child widget's constructor with the QStackedWidget's address, or calling QStackedWidget::insertWidget(), or both? 我应该使用QStackedWidget的地址调用子部件的构造函数,还是调用QStackedWidget :: insertWidget()或同时使用两者?

I would advise creating the child widget and then passing it to QStackedWidget::insertWidget or QStackedWidget::addWidget. 我建议创建子窗口小部件,然后将其传递给QStackedWidget :: insertWidget或QStackedWidget :: addWidget。 This is the method the Qt people call out in their documentation . 这就是Qt人们在他们的文档中提到的方法。 If you pass the QStackedWidget in as the parent to the children, I don't know if you get any guarantee that they're actually added to the QStackedWidget's underlying layout. 如果您将QStackedWidget作为父级传递给子级,我不知道您是否可以保证它们实际上已添加到QStackedWidget的基础布局中。 Doing both seems to be overkill and is unnecessary. 两者都似乎是多余的,并且是不必要的。 By calling insertWidget or addWidget, you are guaranteed they are added to the layout. 通过调用insertWidget或addWidget,可以确保将它们添加到布局中。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM