Reputation: 36101
I have a QTabBar, and all tabs are supposed to have the same widget in them:
layout1->addWidget(w);
layout2->addWidget(w);
However calling addWidget
the second time causes this widget to disappear in the first layout.
Is there any way to use one widget to insert it in several tabs?
Of course I can always create a new widget instance for every tab, but that takes extra time and memory.
Upvotes: 6
Views: 3188
Reputation: 17535
Is there any way to use one widget to insert it in several tabs?
No. If you want the widget to be seen twice, then you need two instances of it.
Of course I can always create a new widget instance for every tab, but that takes extra time and memory.
Simple widgets are relatively cheap in regards to memory/time to create. Unless your GUI is becoming unresponsive and your profiler says that this is a problem, you are likely attempting a premature optimization.
Depending on the specific goal you're trying to accomplish, there are patterns such as using multiple views that share a single model that can potentially be employed.
Upvotes: 6