December 1, 2011

m3rlin m3rlin
Lab Rat
2 posts

Parent/Child Forms

 

HI,

I am new to QT Qt(4) and very excited to begin programming. I have 6 years VB programming background and < 1 year C++.
I work on a Linux Box using QT Qt Designer and Gedit :)
I am getting into the C and QT Qt Jargon but I am having trouble finding the right documentation for several subjects.

My question: How do I program the following relationships in QT Qt/C++?

Form-A has a menu and a tool bar. When a menu-item is clicked I’d like Form-B to be displayed inside form-A. Form-B is a form hosting form-C, form-D, and form-E. (like in an HTML Frame where you load multiple .html files inside a mainform.html).

Please consider the following in your answer:

  • I do not want to use MDI.
  • I really want to use a separate form for each layout and not 1 big main form with hiding panels and layouts
  • When opening multiple forms inside an opened form I need to be able to pass data (as delegate I guess) (in)between the forms. For example: A button click in form-D causes data to be loaded in form-E from a SQL database. Form-D and form-E are part of form-B. Form B was loaded inside form-A…

Thank you, you help is appreciated.

5 replies

December 1, 2011

fluca1978 fluca1978
Lab Rat
472 posts

I think you should implement each form as a separate widget and use a qstackedlayout [doc.qt.nokia.com] as the layout for the main window. In this way only one widget will be visible at a time.

December 1, 2011

Andre Andre
Robot Herder
6422 posts

You may also be interested in the convenient QStackedWidget.

To pass messages, delegates are not the way to go. A delegate is used for rendering content in an item view. Instead, you should read about using signals and slots [developer.qt.nokia.com] .

To prevent futher communication issues, what you call a form is called a widget in Qt lingo. A top-level widget is shown as a window on your system, and is sometimes called a form. All visible elements are widgets: buttons, text edits, forms and tabs, but also complete dialogs and main windows.

December 1, 2011

m3rlin m3rlin
Lab Rat
2 posts

fluca1978,

Thanks for your quick reply.
I see – every form is to be made into a widget ?!?
I should then host multiple widgets on 1 base form which in itself is a widget (container).

Aha…

December 1, 2011

fluca1978 fluca1978
Lab Rat
472 posts

m3rlin wrote:
fluca1978,

Thanks for your quick reply.
I see – every form is to be made into a widget ?!?
I should then host multiple widgets on 1 base form which in itself is a widget (container).

Aha…

Yes, the idea is that. You can stack widget one within the other to achieve much more complex widgets (forms). Then you can even stack them together using a stack layout into a one big container.
As Andre said, each widget can emit and handle signals, which can be thought as the equivalent of an event. So a button in your form A can emit a clicked signal that can be handled by your form B to load additional data and the save action on form B can cause a refresh back to forms A and C…..and so on.

December 1, 2011

m3rlin m3rlin
Lab Rat
2 posts

@Andre and fluca1978,

I am loving it already…
Thank you both.

I will get the jargon right soon! Takes a while to “signal” from 1 braincell widget to the other :)

 
  ‹‹ Convert IplImage to QByteArray      Bad ptr when passing an argument ››

You must log in to post a reply. Not a member yet? Register here!