In my current project, I'm trying to write a custom Widget and have Actions work with the widget.
For example, I need to select some entities, then filter and compose some other shapes. I have this working without issue.
My problem is that I do not understand how to discern between the "action" that is the Widget and the "action" that would be the components.
For example, I have my widget which is attached to a ShowWidget action. I have two buttons on this UI to interact with the CAD window, which I currently accomplish by using the action underlying the "ShowWidget". The means to do this is by maintaining multiple states of actions within the single action of the "ShowWidget." This seems cluttered and means I always have an action running, thus cluttering the action stack.
My question thus becomes: How can I specify an action using the EAction system that I can enact via a simple QPushButton? (I realize I may give too much information, I said it to give context incase my question doesn't actually solve my problem.. )
Thanks!
[SOLVED] Custom UI + Actions
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
[SOLVED] Custom UI + Actions
Last edited by Nava2 on Mon Jan 05, 2015 9:58 pm, edited 1 time in total.
Re: Custom UI + Actions
I tried splitting things into their own EAction sub-classes, then creating the new action myself. The issue is that if I need access to the Document I can't use getDocument, the action stack also doesn't appear to work properly.
Any advice is appreciated.
Any advice is appreciated.
Re: Custom UI + Actions
Note that a widget is not an action. There might be an action that can be used to show / hide the widget and a widget might be created by an action's init method, but the widget itself lives independently of that action once it is created.
The recommended way to assign an action to a push button, tool button, context menu, etc, is to look up its GUI action and make it the default action for the button, menu, etc:
The recommended way to assign an action to a push button, tool button, context menu, etc, is to look up its GUI action and make it the default action for the button, menu, etc:
var action = RGuiAction.getByScriptFile("scripts/Draw/Line/Line2P/Line2P.js"); myToolButton.setDefaultAction(action);The icon, text and tooltip of the GUI action are automatically used to decorate the button.
Re: Custom UI + Actions
Yup, I figured this out based on the Widgets in scripts/Widgets. Thanks!andrew wrote:Note that a widget is not an action. There might be an action that can be used to show / hide the widget and a widget might be created by an action's init method, but the widget itself lives independently of that action once it is created.
So, I solved this using a different approach. Given the Widget I have, I used the R*ListenerAdapter interfaces to create listeners based on states to implement my requirements. This makes sense for now. Ideally, I'll move the actions into RGuiActions and use the Toolbars later.andrew wrote: The recommended way to assign an action to a push button, tool button, context menu, etc, is to look up its GUI action and make it the default action for the button, menu, etc:
var action = RGuiAction.getByScriptFile("scripts/Draw/Line/Line2P/Line2P.js"); myToolButton.setDefaultAction(action);The icon, text and tooltip of the GUI action are automatically used to decorate the button.