How to reuse QLayout in new tabs?
-
Hi!
I have a layout I want to use in several tabs. What is the intended way to do it? QObjects aren't supposed to be copied and I can't use the same layout for two widgets (problem: QLayout already has a parent), right? Do I have to rewrite the code for every tab?
Hanna
-
I would say the name of the class might be a bit confusing. QLayout and its subclasses may hold the specifics defining a layout, but it is not really the layout. The specifics are set typically through some routines for your tab. If you want to use specifics of a layout for another tab simply use the routine again. Respectively all content of a tab is generated through some and you would use the same routine when you create a replic of it.
-
Hi,
@Hanna-Larsson said:
I have a layout I want to use in several tabs.
Do you mean you want the different tabs to look exactly the same?
Do I have to rewrite the code for every tab?
No need to rewrite all the code. You can write one function that generates the layout and its children. Call that function for each tab.
-
@Hanna-Larsson said:
@JKSH I want the tabs to have the same layout so that when a widget is added it is placed in a specific way.
If you want two tabs to have the same layout, then you must create two separate QLayout objects.