PDA

View Full Version : Invoking New Dialog



kb1lqc
5th November 2009, 14:26
So maybe this is right under my nose but I cannot seem to figure out how to invoke a new dialog. What I want to do is have a main menu, from there the user can select a button such as "Apps" where a new dialog is displayed. This would ideally cause the main menu to be hidden or disappear when the "Apps" menu comes up. Would this be a parent - child issue? I am also not sure on how to set this up with code. Does anyone have any examples with a short explanation?



Bryce

lyuts
5th November 2009, 15:02
Qt has a lot of examples (with source code). The things you need can be found there.

kb1lqc
5th November 2009, 15:18
Qt has a lot of examples (with source code). The things you need can be found there.

Yes I know. I have been reading through them as well as looking through the book C++ GUI Programming With Qt 4. However I'm not quite getting the concept. It seems as though I need to create a new class for each menu? I was trying to do a "MainMenu" class where I would have member functions such as MainMenu::Menu1, MainMenu::Menu2, etc. Now it looks as though I many need to have a new class for each menu, would this be correct?


Bryce

lyuts
5th November 2009, 15:29
Ok, let's say you have a QMenuBar (http://doc.trolltech.com/4.5/qmenubar.html#details). If you look at this documentation, then you will see that you can easily add more menus to this menubar. One of this menu will have "Apps" item in it (after you add it).
Hint: You can add this item with the following QMenuBar's (or QMenu's) method:


QAction * addAction ( const QString & text, const QObject * receiver, const char * member );


when you use it for your "Apps" item you actually say "when the item with that says <text>(in your case Apps) is pressed, i want to execute <member> method, and my the way, <receiver> has this method".

The next thing you do is implement this method which in fact does the following:
1. Create QDialog (http://doc.trolltech.com/4.5/qdialog.html). (or it may be already been created, it depends on your design).
2. Show this dialog.

kb1lqc
5th November 2009, 15:57
Ok, let's say you have a QMenuBar (http://doc.trolltech.com/4.5/qmenubar.html#details). If you look at this documentation, then you will see that you can easily add more menus to this menubar. One of this menu will have "Apps" item in it (after you add it).
Hint: You can add this item with the following QMenuBar's (or QMenu's) method:


QAction * addAction ( const QString & text, const QObject * receiver, const char * member );


when you use it for your "Apps" item you actually say "when the item with that says <text>(in your case Apps) is pressed, i want to execute <member> method, and my the way, <receiver> has this method".

The next thing you do is implement this method which in fact does the following:
1. Create QDialog (http://doc.trolltech.com/4.5/qdialog.html). (or it may be already been created, it depends on your design).
2. Show this dialog.

Ok and this is applicable to a QPushButton as well? That was one of my main areas of confusion when reading the sections about creating menus and toolbars the the Qt 4 book.

lyuts
5th November 2009, 16:13
Yes. As for this QMenuBar, you will not need QPushButton for it.

kb1lqc
5th November 2009, 16:14
Yes. As for this QMenuBar, you will not need QPushButton for it.

I think I didn't explain my application very well! I want to open the new dialog by pressing a QPushButton, does this apply to it? I do not wish to have a QMenuBar.


Thanks for the help,
Bryce

lyuts
5th November 2009, 16:19
Oh, got it.

Well, you will have your main window or main dialog which will have the desired QPushButton (in fact, it will be this button's parent). Besides this window/dialog will have a slot which will have the code for creating a new dialog and showing it. Connect this button's signal clicked() with your slot and that's it.

kb1lqc
5th November 2009, 16:23
Oh, got it.

Well, you will have your main window or main dialog which will have the desired QPushButton (in fact, it will be this button's parent). Besides this window/dialog will have a slot which will have the code for creating a new dialog and showing it. Connect this button's signal clicked() with your slot and that's it.

Thanks for the help I'll let you know what happens. I appreciate the help.


Bryce