QTabWidget: Add new Tab from a QWidget tab
Philipp DE last edited by
I my application, I have a QTabWidget with several tabs.
On tab of that QTabWidget is inside an QWidegt and I add this like
ui->tabWidget->insertTab(1, new FormMember(0, this), "New Member");
Until here, everything works fine.
Now I am inside that FormMember Class (QWidget) and I like to create a new tab for my QTabWidget from there.
I have no Idea how I can access to that QTabWidget (which is not part of my FormMember class) object to add a new tab.
What would be the right way. Do I need to give a pointer as further parameter to my FormMember class or is there any better way to receive this.
When I was working with c++ Builder 20 years ago it was no problem to call other object from other windows.
JonB last edited by JonB
You should really do this from the
ui->tabWidgetlevel, or send it a signal asking it to create another tab.
But if you do want to be able to access the
FormMember, as you say you could pass the
FormMemberto store (naughty), or you can use
parentWidget()(I think the latter) to walk up the hierarchy (you may have to go a couple of steps, not just one, can't recall) till you hit a
qobject_cast<QTabWidget*>(parent) != nullptr, and that will be the parent
Use @JonB first suggestion. Implement a proper API for that. Toying with parent widgets is usually sign of a wrong design.