简体   繁体   中英

Qt::QStackedWidget insert vs child widget constructor call

Using a QStackedWidget, what is the best practice for placing a widget on it? should I be calling the child widget's constructor with the QStackedWidget's address, or calling QStackedWidget::insertWidget(), or both?

I would advise creating the child widget and then passing it to QStackedWidget::insertWidget or QStackedWidget::addWidget. This is the method the Qt people call out in their documentation . 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. Doing both seems to be overkill and is unnecessary. By calling insertWidget or addWidget, you are guaranteed they are added to the layout.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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