[Interest] Two different layouts?

John Weeks john at wavemetrics.com
Wed Aug 14 23:06:54 CEST 2019


I have a moderately complex window (more than 50 QWidget- and QLayout-derived components). I have decided that it would be nice to have two versions: a vertical layout and a horizontal layout. But it's not just a matter of QVBoxLayout vs QHBoxLayout.

I have developed a new .ui file with the vertical layout and the appropriate rearrangement of the widgets. All the widgets are the same, with the same names. The QLayout-derived items are different, but my code doesn't need to access them.

It would be great if I could instantiate one or the other of these layouts at run-time and get back a pointer (or something?) that I could use instead of the usual ui-> pointer. The members that I need to reference all have the same names in the two .ui files. Seems like there should be a C++ template way to do this, but I'm not as clever with that kind of stuff as I might be.

Has anyone developed a solution to this? Or do I need to make a wrapper class that has an accessor function for each of the widgets? That would be a pain to implement, and a source of bugs in the future when I change the layouts.

Any ideas greatly appreciated.

-John Weeks



More information about the Interest mailing list