[Interest] Two different layouts?

john at wavemetrics.com john at wavemetrics.com
Sat Aug 17 02:15:38 CEST 2019


Thank you! That might be what I want. I'll check it out on Monday.

> On Aug 16, 2019, at 3:24 PM, Israel Brewster <ijbrewster at alaska.edu> wrote:
> 
> On Aug 14, 2019, at 1:06 PM, John Weeks <john at wavemetrics.com> wrote:
>> 
>> 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
>> 
> 
> It sounds like you may be looking for the QUiLoader Class (https://doc.qt.io/qt-5/quiloader.html)? Create an empty QMainWindow (in code), then at runtime in the constructor of said window load the proper UI file using the QUILoader (what it loads is your ui-> pointer), and use the setCentralWidget() method of the window to set the widgets from the UI file into the window. I think that’s how it goes :-)
> 
> ---
> Israel Brewster
> Software Engineer
> Alaska Volcano Observatory 
> Geophysical Institute - UAF 
> 2156 Koyukuk Drive 
> Fairbanks AK 99775-7320
> Work: 907-474-5172
> cell:  907-328-9145
> 
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> https://lists.qt-project.org/listinfo/interest
> 

-John




More information about the Interest mailing list