On 8/14/19 11:15 PM, John Weeks  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.

Had to do that under 4.8 years ago for a medical device touch screen. We had everything configured in "bricks" for vitals readings and based on the current patient "profile" not only did the arrangement of the bricks change but their sizes.

I'm kind of busy this weekend. Drop me a note off-list if you really need me to look it up. I may have some of the stuff laying around. Here's the thumbnail sketch.

You aren't granular enough.

Our bricks were really complex. They had a lot of stuff going on in them despite their tiny size. By and large they were autonomous. They were in one big widget contained in a stacked widget. When the big widget became visible it looked at the current patient profile and last manual arrangement (yes, the user could manually re-arrange via dragging) then re-displayed the widgets in the correct order and size. (A user could have been on a configuration or patient screen which caused the current patient profile to change.)

In short, you don't have enough functionality in your objects if you are trying to use ui-> directly in a main window.

IF you are really insisting on your current architecture then create one big widget which contains a stacked widget and create an instance of one UI in one frame and the other in another frame and an access function in the big widget class.

I don't know if any of your widgets are connecting to devices/database/whatever and I don't know if they do anything global-ish so I don't know if having two different instances will cause you a problem.

The shortest of short answers is to make each widget its own UI file and delete the UI files you currently have. Create each of the UI instances once and have the main window decide where to place them when it becomes visible.

--
Roland Hughes, President
Logikal Solutions
(630)-205-1593  (cell)
http://www.theminimumyouneedtoknow.com
http://www.infiniteexposure.net
http://www.johnsmith-book.com

_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to