Qt: using one widget in several layouts

岁酱吖の 提交于 2020-01-14 12:34:47

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/10047321/qt-using-one-widget-in-several-layouts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!