[Interest] Two different layouts?
ijbrewster at alaska.edu
Sat Aug 17 00:24:00 CEST 2019
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 <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 :-)
Alaska Volcano Observatory
Geophysical Institute - UAF
2156 Koyukuk Drive
Fairbanks AK 99775-7320
> Interest mailing list
> Interest at qt-project.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Interest