[Qt-interest] Linking toolbar/menu QAction to widget QAction

John McClurkin jwm at nei.nih.gov
Fri May 15 13:42:27 CEST 2009


Mildred Ki'Lya wrote:
> Hi,
> 
> Is there a way to link QActions together?
> 
> Let me explain.
> 
> We have a toolbar with various actions, and the main window contains 
> many different widgets (derived from QTableView) organized in tabs. I 
> would like the toolbar actions to redirect to the similar action on the 
> focused widget.
> 
> For now, each toolbar action triggers a slot in the main window that 
> lookup the focused widget and call the appropriate method. But when the 
> action becomes unavailable for the focused widget, or when there are no 
> focused widgets, I would like to disable the toolbar actions as well.
> 
> I think the best approach would be to link the toolbar actions to the 
> actions of the current focused widget. So, if there is no focused widget 
> or if the widget's action is disabled, the toolbar action becomes 
> unavailable.
> 
> Do you know a way to achieve that?
> 
> Thanks.
> 
> Mildred
> 
> 
This solution will depend on where the tabs for the different widgets 
are handled. I suggest that you connect the action signal from the 
toolbar actions to a signal in main window, not to a slot. In main 
window code, connect that signal to a slot in the widget in the tabbed 
view. Finally, as part of the slot called when you click a tab to show a 
new widget, disconnect the window signal from the previous view's 
widget's slot and connect the signal to the new view's widget's slot. If 
a view has no widget, no connection will be made and clicking the 
toolbar's action will send a signal harmlessly into space.



More information about the Qt-interest-old mailing list