[SOLVED] Custom UI + Actions

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
Nava2
Junior Member
Posts: 15
Joined: Sun Oct 26, 2014 6:01 pm

[SOLVED] Custom UI + Actions

Post by Nava2 » Wed Dec 31, 2014 2:21 am

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!
Last edited by Nava2 on Mon Jan 05, 2015 9:58 pm, edited 1 time in total.

Nava2
Junior Member
Posts: 15
Joined: Sun Oct 26, 2014 6:01 pm

Re: Custom UI + Actions

Post by Nava2 » Sat Jan 03, 2015 1:40 am

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.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Custom UI + Actions

Post by andrew » Mon Jan 05, 2015 3:06 pm

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:
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.

Nava2
Junior Member
Posts: 15
Joined: Sun Oct 26, 2014 6:01 pm

Re: Custom UI + Actions

Post by Nava2 » Mon Jan 05, 2015 9:57 pm

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.
Yup, I figured this out based on the Widgets in scripts/Widgets. Thanks!
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.
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.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”