QTabWidget: Add new Tab from a QWidget tab
-
Hi,
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.
-
Hi,
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.
@Philipp-DE
You should really do this from theui->tabWidgetlevel, or send it a signal asking it to create another tab.But if you do want to be able to access the
tabWidgetfrom yourFormMember, as you say you could pass thetabWidgetforFormMemberto store (naughty), or you can useFormMember'sparent()orparentWidget()(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 aqobject_cast<QTabWidget*>(parent) != nullptr, and that will be the parentQTabWidget.