Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Solved]Will QTabWidget::addTab() set the parent for the widget handed over as parameter?



  • I guess the title says it all. If I do this:

    @tabWidget->addTab(myParentlessWidget, "text");@

    Will "myParentlessWidget" have a parent widget set automatically?



  • Yes, the QStackedWidget inside QTabWidget becomes the new parent.



  • thank you Lukas


  • Moderators

    Add
    @
    if (myParentlessWidget->parent())
    qDebug() << "GOT A PARENT NOW!";
    @

    after your code and check the output... That should produce results faster than posting on a forum;-).



  • [quote author="Tobias Hunger" date="1330010028"]Add
    @
    if (myParentlessWidget->parent())
    qDebug() << "GOT A PARENT NOW!";
    @

    after your code and check the output... That should produce results faster than posting on a forum;-).[/quote]
    :-)
    The "Just try it" mentality is not all that wide-spread anymore, I'm afraid...



  • Damn it's so simple. I feel kind of silly now for not thinking of that myself.



  • In doubt I usually just take a look at the sources. Done in a minute and I can be absolutely sure what's going on. Plus, you learn a lot about Qt and its internals.



  • I added a "DocNote":/doc/qt-4.8/qtabwidget.html#notes for future reference. Feel free to add those yourself, in case you have the answer of a question like this!


Log in to reply