View Full Version : Disable menu item based to current control selected
Suppaman
8th December 2010, 15:56
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
tbscope
8th December 2010, 16:03
Signals and slots
Suppaman
8th December 2010, 16:05
What signal or what slot? Can you make a short example?
tbscope
8th December 2010, 16:09
Suppose you have a QListWidget, it has an itemClicked signal
http://doc.qt.nokia.com/4.7/qlistwidget.html#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.
marcvanriet
9th December 2010, 00:17
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
Suppaman
9th December 2010, 07:33
Hi
This is the same solution I started to develop. However thank you for the confirmation the solution is good. :)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.