Right Click Context Menu

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
cjh
Active Member
Posts: 31
Joined: Tue Jul 12, 2016 4:51 pm

Right Click Context Menu

Post by cjh » Thu Oct 13, 2016 8:51 pm

How do I add an action to the right click context menu?
If I right click a block, the "Edit Block" action is an option.
Where is that context menu defined?
I would like to add custom actions to the right click block context menu.

Connor

User avatar
Husky
Moderator/Drawing Help/Testing
Posts: 4935
Joined: Wed May 11, 2011 9:25 am
Location: USA

Re: Right Click Context Menu

Post by Husky » Fri Oct 14, 2016 6:54 pm

Hi Connor,
cjh wrote:I would like to add custom actions to the right click block context menu.
unfortunately the context menu isn't adjustable and in my opinion why it should be? It's a context menu ...

However, I'm curious: What kind of tools would you like to add to the menu?
Work smart, not hard: QCad Pro
Win10/64, QcadPro, QcadCam version: Current.
If a thread is considered as "solved" please change the title of the first post to "[solved] Title..."

cjh
Active Member
Posts: 31
Joined: Tue Jul 12, 2016 4:51 pm

Re: Right Click Context Menu

Post by cjh » Fri Oct 14, 2016 7:19 pm

The right-click context menu already shows different options for different entities, so that adjustment has to occur somewhere!

I just can't trace it beyond when the RMainWindowQt emits contextmenu((int)entityId, pos) signal.

If you right click a block, the context menu gives an Edit Block option at the bottom.
If you right click a line, you have the options to Deselect Contour and Auto Create Polyline.

I would like to right click a block and have the option to run a custom action to "Assign Parts" to the block.
It will show a dialog to assign custom properties to the block by pulling part list info from a database.

Using these custom properties, I can auto-create a bill of materials to appear on the drawing.

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

Re: Right Click Context Menu

Post by andrew » Fri Oct 14, 2016 7:39 pm

It's not possible to extend the context menu in the current version.

However, you can replace it with your own:

MyContextMenu.js:

Code: Select all

include("scripts/Pro/Widgets/ContextMenu/ContextMenu.js");

function MyContextMenu() {
}

MyContextMenu.init = function(basePath) {
    var appWin = RMainWindowQt.getMainWindow();
    // register (connect context menu):
    appWin.contextMenu.connect(MyContextMenu, "showEntityContextMenu");
};

MyContextMenu.postInit = function() {
    // disconnect (disable) current context menu:
    ContextMenu.disconnect();
};

// This is called when the user right-clicks an entity
MyContextMenu.showEntityContextMenu = function(entityId) {
    var doc = EAction.getDocument();
    var entity = doc.queryEntity(entityId);
    
    var menu = new QMenu(RMainWindowQt.getMainWindow());
    ...
    menu.exec(QCursor.pos());
};
I've also refactored ContextMenu for the next release, so you can get and extend the QCAD standard context menu:

Code: Select all

var menu = ContextMenu.getContextMenu(entityId);

cjh
Active Member
Posts: 31
Joined: Tue Jul 12, 2016 4:51 pm

Re: Right Click Context Menu

Post by cjh » Fri Oct 14, 2016 7:46 pm

Ahhh that's why I couldn't find it!

I'll wait for the next release before working with it.

Thanks Andrew!

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”