Results 1 to 6 of 6

Thread: Disable menu item based to current control selected

  1. #1

    Default Disable menu item based to current control selected

    Hi

    I need to enable/disable some items into main menu based if a control is selected or not. For example I have a list control and in the menu two items, "create" and "delete". I want to show as disabled the item "delete" if there is no selection in the list.

    How is possible to do this with Qt?

    Thank you

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Disable menu item based to current control selected

    Signals and slots

  3. #3

    Default Re: Disable menu item based to current control selected

    What signal or what slot? Can you make a short example?

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Disable menu item based to current control selected

    Suppose you have a QListWidget, it has an itemClicked signal
    http://doc.qt.nokia.com/4.7/qlistwid...ml#itemClicked

    A menu is made out of actions (QAction). This has a slot setEnabled
    http://doc.qt.nokia.com/4.7/qaction.html#enabled-prop

    In the slot connected to the itemClicked signal, check which item is selected and then based on that select the correct action in the menu and use the setEnabled slot.

  5. #5
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Disable menu item based to current control selected

    Hi,

    I usually create a function that updates the status of action buttons and menu items and the like, depending on the contents of the user fields.

    Whenever a field is changed (or in your case, whenever an item is deleted or added to the list), I call this function and my menu items get updated.

    Best regards,
    Marc

  6. #6

    Default Re: Disable menu item based to current control selected

    Hi

    This is the same solution I started to develop. However thank you for the confirmation the solution is good.

Similar Threads

  1. QAxServer-based ActiveX control crashes gdb
    By barbicels in forum Qt Programming
    Replies: 0
    Last Post: 15th September 2010, 17:12
  2. Replies: 1
    Last Post: 20th January 2010, 09:38
  3. Changing selected item color in non-current window.
    By Doug Broadwell in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2007, 08:09
  4. How to know the current tab selected
    By Mrdata in forum Newbie
    Replies: 11
    Last Post: 6th February 2007, 20:46
  5. Replies: 14
    Last Post: 9th November 2006, 09:35

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.