PDA

View Full Version : Menu Actions



GrahamLabdon
16th April 2010, 10:52
Hi
I am new QT and am using the Visual Studio addin.
I have created a main window and used QT Designer to add a File menu with an Exit member. I have used WT Designer to add an action to this member, but I cannot seem to figure out how to get it to do something for this action.
I want the application to exit when this is selected
How do I do this?

Thanks

Graham

wysota
16th April 2010, 11:03
There is a signal/slot connection editor in Designer where you can connect the triggered() signal of the action with a close() slot of the form.

GrahamLabdon
16th April 2010, 11:06
It works!!
Thanks

khous11
10th June 2010, 18:20
There is a signal/slot connection editor in Designer where you can connect the triggered() signal of the action with a close() slot of the form.

I have a similar question as GrahamLabdon had. I have created a
MainWindow form with a Menu bar and a Toolbar. I have created several
Menus on the Menu bar. One of the entries on one of the menus is an
Action which I would like to connect to a Dialog form which I have
also created in Qt Designer. I have put the same Action on the
Toolbar and I would also like that connected. How can I get the
triggered() signal of the Action to open the Dialog?

I have tried to use the Signal/Slot Editor (F4) but when I hover over
the Menu bar, the entire Menu bar is highlighted in red. I am not
able to selectivly choose just one menu on the bar and one entry on
the menu.

I have also tried to use the Action Editor and the Property Editor,
but neither of them seem to have access to any signals.

The Qt Designer Manual has some examples in the Examples section, but
none of the examples feature a Menu bar or Toolbar. In the manual
section "Qt Designer's Signals and Slots Editing Mode" there is no
mention of what to do with a Menu bar or Toolbar. In the manual
section "Creating Main Windows in Qt Designer", it discusses Actions,
but fails to say anything about how to connect them.

Thanks for any help you could give me.

JD2000
10th June 2010, 19:34
Write a function that opens the dialog
declare it as a slot in your mainwindow code

open the mainwindow ui
select the menu item
in the signal & slots editor below set
sender - action menu item
signal - triggered
receiver - mainwindow
slot - the function you wrote above

wysota
10th June 2010, 19:43
How can I get the
triggered() signal of the Action to open the Dialog?
Designer operates in the scope of a single form. You can't use cross-reference other forms from it, you need hand written code to do that.

khous11
10th June 2010, 20:35
Write a function that opens the dialog
declare it as a slot in your mainwindow code


Thank you for your help. I am still not sure of how to write a
function that opens the Dialog and how to declare it as a slot. Do
you know of an example or a tutorial already on the Qt site or
wherever that has some example code for opening a Dialog that has been
designed in Qt Designer?

Thanks again.

wysota
10th June 2010, 20:41
I am still not sure of how to write a
function that opens the Dialog and how to declare it as a slot. Do
you know of an example or a tutorial already on the Qt site or
wherever that has some example code for opening a Dialog that has been
designed in Qt Designer?
Did you at least have a look at the main page of Qt reference manual? If not, then do that now, start the search function of your doc browser and type in "tutorial".

khous11
16th June 2010, 00:21
Write a function that opens the dialog
declare it as a slot in your mainwindow code
...


I am having a difficult time finding out how to do those first two
things.

I have tried looking at the tutorials I started with the main page of
the reference manual as you suggested, and I looked at "Creating Main
Windows in Qt Designer" which told me about menus, but has no example
of a menu action starting a dialog designed with Qt Designer. I
looked at "Qt Designer's Signals and Slots Editing Mode" but it of
course only talks about connecting within the same form. I looked at
"Creating Custom Widgets for Qt Designer" but that seemed to be
talking about plugins and did not have an example of a menu action
starting a dialog which has been designed using Qt Designer.

I have designed my dialog and I have the .ui file for the dialog. I
have previewed the dialog in Qt Designer and it looks ready to go.

I also have the menu and the menu action that I would like to use to
start the dialog, and I have previewed the main window in Qt Designer
and that looks good except that clicking the menu item does nothing at
this point.

Can you direct me to an example, or some part of the Qt Designer
Manual, or someplace where a menu action starts a dialog written in Qt
Designer?


Did you at least have a look at the main page of Qt reference manual? If not, then do that now, start the search function of your doc browser and type in "tutorial".

I have tried looking at the tutorials I started with the main page of
the reference manual as you suggested, and I looked at "Creating Main
Windows in Qt Designer" which told me about menus, but has no example
of a menu action starting a dialog designed with Qt Designer. I
looked at "Qt Designer's Signals and Slots Editing Mode" but it of
course only talks about connecting within the same form. I looked at
"Creating Custom Widgets for Qt Designer" but that seemed to be
talking about plugins and did not have an example of a menu action
starting a dialog which has been designed using Qt Designer.

I have designed my dialog and I have the .ui file for the dialog. I
have previewed the dialog in Qt Designer and it looks ready to go.

I also have the menu and the menu action that I would like to use to
start the dialog, and I have previewed the main window in Qt Designer
and that looks good except that clicking the menu item does nothing at
this point.

I just need to know how to get the menu action to start the dialog.
Earlier in this thread JD2000 said "Write a function that opens the
dialog" and "declare it as a slot in your mainwindow code". I just
need to know how to do those two things.

Can you direct me to an example, or some part of the Qt Designer
Manual, or someplace where a menu action starts a dialog written in Qt
Designer?

wysota
16th June 2010, 00:41
I have tried looking at the tutorials I started with the main page of
the reference manual as you suggested, and I looked at "Creating Main
Windows in Qt Designer" which told me about menus, but has no example
of a menu action starting a dialog designed with Qt Designer. I
looked at "Qt Designer's Signals and Slots Editing Mode" but it of
course only talks about connecting within the same form. I looked at
"Creating Custom Widgets for Qt Designer" but that seemed to be
talking about plugins and did not have an example of a menu action
starting a dialog which has been designed using Qt Designer.
Too bad you didn't look at the page called "Tutorials".