Hello,
I am new in QCad, and I am using QCad 13.18.1 pro.
I have to add custom Context Menu for my dxf-files.
Is that possible, and if it is, how can I add it . Is there any example ?
Custom ContextMenu
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Re: Custom ContextMenu
Hello dzenita - welcome to the forum.
Please give us more details about your goal. If possible with an example screenshot or drawing. Thanks.dzenita wrote:I have to add custom Context Menu for my dxf-files.
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: Custom ContextMenu
I am coding and I want do extend context menu in a script. Is that possible ?
I am writing company specific extension, and I want to put them inside right click menu.
In attachment is an example.
I am writing company specific extension, and I want to put them inside right click menu.
In attachment is an example.
- Attachments
-
- example1.png (98.11 KiB) Viewed 4177 times
Re: Custom ContextMenu
Please place this code in a file for example under scripts/Misc/Examples/CustomContextMenu/CustomContextMenu.js:
The code adds a custom entry "My Action" to the standard context menu of QCAD and should hopefully be self-explanatory.
Code: Select all
include("scripts/Pro/Widgets/ContextMenu/ContextMenu.js");
function CustomContextMenu() {
}
CustomContextMenu.prototype = new Object();
CustomContextMenu.postInit = function(basePath) {
// disable default context menu:
ContextMenu.disconnect();
// initialize custom context menu:
var appWin = RMainWindowQt.getMainWindow();
appWin.contextMenu.connect(CustomContextMenu, "showContextMenu");
};
/**
* This is called when user right clicks into empty space or on an entity.
*
* \param entityId ID of entity that was clicked (context) or RObject.INVALID_ID if
* context is empty space.
* \param pos Position of the click in drawing coordinates.
*/
CustomContextMenu.showContextMenu = function(entityId, pos) {
// get the detault context menu from QCAD:
var menu = ContextMenu.getContextMenu(entityId, pos);
// add a custom action:
var action = menu.addAction("My Action");
action.triggered.connect(CustomContextMenu, "myAction");
// show context menu:
if (!isNull(menu) && !menu.isEmpty()) {
menu.exec(QCursor.pos());
}
};
/**
* This is called when user clicks "My Action" in context menu.
*/
CustomContextMenu.myAction = function() {
EAction.handleUserMessage("My Action Triggered");
};
Re: Custom ContextMenu
Thanks a lot Andrew
It works
It works