I have a few combo-boxes and double spin boxes on my Qt Dialog. Now I need a ‘ResetToDefault’ item on a menu that comes up when you right click on the widget (spin box or combo box).
How do i get it. Is there some way I can have a custom menu that comes up on right click or Is there a way i can add items to the menu that comes on right click.
First, for Qt4, the simplest way is to create an action to reset the data, and add it the the widget using the
addActionmethod (or use the designer). Then, set thecontextMenuPolicyattribute toQt::ActionsContextMenu. The context menu will appear and the action will be triggered.Code example:
For Qt3, you might have to intercept the context menu event, and thus inherit the QSpinBox and others. Or maybe you can intercept the context menu event from the main window, detect if it occurred above the widget supposed to have a context menu (using the
QWidget::childAtmethod) and show it there. But you’ll have to test.