Results 1 to 10 of 10

Thread: Menu Actions

  1. #1
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Menu Actions

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Menu Actions

    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.

  3. The following user says thank you to wysota for this useful post:

    GrahamLabdon (16th April 2010)

  4. #3
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Menu Actions

    It works!!
    Thanks

  5. #4
    Join Date
    Jun 2010
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Menu Actions

    Quote Originally Posted by wysota View Post
    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.

  6. The following user says thank you to khous11 for this useful post:

    JD2000 (10th June 2010)

  7. #5
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Menu Actions

    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
    Got to keep the loonies on the path ...

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Menu Actions

    Quote Originally Posted by khous11 View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #7
    Join Date
    Jun 2010
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Menu Actions

    Quote Originally Posted by JD2000 View Post
    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.

  10. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Menu Actions

    Quote Originally Posted by khous11 View Post
    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".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #9
    Join Date
    Jun 2010
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default

    Quote Originally Posted by JD2000 View Post
    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?

    Quote Originally Posted by wysota View Post
    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?
    Last edited by wysota; 16th June 2010 at 00:39.

  12. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Menu Actions

    Quote Originally Posted by khous11 View Post
    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".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Adding actions to a context menu
    By aarelovich in forum Qt Programming
    Replies: 4
    Last Post: 7th December 2011, 12:47
  2. Toolbar/menu actions with radio behavior?
    By brcain in forum Qt Programming
    Replies: 1
    Last Post: 15th January 2010, 22:10
  3. Replies: 12
    Last Post: 21st November 2008, 04:42
  4. copy/paste actions in main window menu
    By magland in forum Qt Programming
    Replies: 3
    Last Post: 2nd October 2007, 12:33
  5. menu actions calling a single slot
    By jayw710 in forum Qt Programming
    Replies: 2
    Last Post: 28th June 2007, 19:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.