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
Right Click Context Menu
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.
Re: Right Click Context Menu
Hi Connor,
However, I'm curious: What kind of tools would you like to add to the menu?
unfortunately the context menu isn't adjustable and in my opinion why it should be? It's a context menu ...cjh wrote:I would like to add custom actions to the right click block 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..."
Win10/64, QcadPro, QcadCam version: Current.
If a thread is considered as "solved" please change the title of the first post to "[solved] Title..."
Re: Right Click Context Menu
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.
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.
Re: Right Click Context Menu
It's not possible to extend the context menu in the current version.
However, you can replace it with your own:
MyContextMenu.js:
I've also refactored ContextMenu for the next release, so you can get and extend the QCAD standard context menu:
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());
};
Code: Select all
var menu = ContextMenu.getContextMenu(entityId);
Re: Right Click Context Menu
Ahhh that's why I couldn't find it!
I'll wait for the next release before working with it.
Thanks Andrew!
I'll wait for the next release before working with it.
Thanks Andrew!