Qt: using one widget in multiple layouts
I have a QTabBar and all tabs need to have the same widget in them:
layout1->addWidget(w); layout2->addWidget(w);
However, calling a addWidget
second time makes this widget disappear in the first layout.
Can I use one widget to insert it into multiple tabs?
Of course, I can always create a new instance of the widget for each tab, but this takes extra time and memory.
source to share
Can I use one widget to insert it into multiple tabs?
Not. If you want the widget to be viewed twice, you need two instances.
Of course, I can always create a new instance of the widget for each tab, but this takes extra time and memory.
Simple widgets are relatively cheap in terms of memory / build time. If your GUI keeps responding and your profiler says this is a problem, you are probably trying to do a premature optimization.
Depending on the specific purpose you are trying to accomplish, there are patterns such as using multiple views that use a single model that can potentially be used.
source to share