Back to Blog home

Extending Qt Bridge

Published on Thursday January 09, 2020 by Vikas Pachdha in Qt Design Studio Qt Bridge | Comments
Qt Design Studio is the latest offering from The Qt Company. It's an easy-to-use design tool that lets designers import designs from Sketch and Photoshop to Qt, animate them, test them live on the target hardware, and turn them into QML code developers can use.
 
The Qt Bridge is the plugin component for the design tools like Photoshop and Sketch. The plugin primarily enables designers to annotate the design document's layers and exports these annotations along with the assets and DOM of the design document into an intermediate format which can be imported in the QDS. The plugin is developed using Javascript and uses APIs exposed by the design tools. See Qt Bridge documentation for more details about the plugin. 
 
Qt Bridge plugin version 1.4 onwards allows users to write a JSX script to extend or customise the Qt Bridge plugin behaviour for Photoshop. The settings screen allows the user to select the custom script. The script is evaluated when the plugin loads.

Override script settings

APIs

Following APIs can be defined in the JSX file to customise or extend the Qt Bridge behaviour.

  • preExport(documentInstance)

    The preExport(...) API is called before the PSD document is exported. The document instance is sent as an argument. The user can make changes to the document and, if required, revert those changes once the export is done by defining postExport(...) API.

    Details about Photoshop object model are available at https://www.adobe.com/devnet/photoshop/scripting.html

  • postExport(documentInstance)

    The postExport(...) API is called after the PSD document is exported. The document instance is sent as an argument. The user can make changes to the document instance. For example you might want to revert the changes made to the document in the preExport(...) API.

  • customQmlId(generatedQmlId, psdLayerInstance)

    The API customQmlId(...) is called every time a default QML id is generated for a PSD layer and user can return the QML id to be assigned to the layer. The parameter generatedQmlId is the default QML id generated by the Qt Bridge plugin for the layer and the parameter layerInstance is the PSD layer object.

    Note: Return null to use the default generated QML id. 

 

Example override JSX:

The following script logs the export start and finish of the exported PSD document to a export.log file inside the home directory. The QML Ids are  prefixed with "m_" and the document and layer ids are removed.

 

myCustomScript.jsx
var logFile = null

preExport = function (documentInstance) {
    if (openLogFile("~/export.log")) {
        var date = new Date();
        logFile.writeln(date + ": Exporting: " + documentInstance.name);
    }
}

postExport = function (documentInstance) {
    if (logFile) {
        var date = new Date();
        logFile.writeln(date + ": Exporting done: " + documentInstance.name);
        logFile.close();
    }
}

customDefaultQmlId = function(generatedQmlId, psdLayerInstance) {
    return "m_" + generatedQmlId.replace(/_[0-9]*_[0-9]*$/g, "");
}


function openLogFile(path) {
    logFile = new File(path);
    var fileCreated = false;
    return logFile.open("w");
}

Report bugs and suggestions at https://bugreports.qt.io/projects/QDS/

Subscribe to Our Blog

Stay up to date with the latest marketing, sales and service tips and news.