nodeguy/website/docs/api/manual/synopsis.md
Atul R 392aa3cd4c
Adds automatic docs for now (#308)
* adds basic typedoc

* backup

* Adds all docs to source code

* Adds autogenerated docs

* Fixes doc links

* Updates docs
2019-12-29 00:42:06 +05:30

1.7 KiB

sidebar_label title
Synopsis Synopsis

How to use Node.js and NodeGui's APIs.

All of Node.js's built-in modules are available in NodeGui. Also, third-party node modules that are known to work with Node.Js are fully supported as well (including the native node modules).

Apart from Node.Js ecosystem, NodeGui also provides some extra built-in widget and modules for developing native desktop applications. So, you can think of NodeGui as NodeJs + Gui Widgets powered by Qt.

The app script is like a normal Node.js script:

const { QMainWindow } = require("@nodegui/nodegui");

const win = new QMainWindow();

win.show();

global.win = win; // To prevent win from being garbage collected.

To run your app, read Run your app.

Destructuring assignment

You can use destructuring assignment to make it easier to use built-in modules.

const {
  QMainWindow,
  QWidget,
  QLabel,
  FlexLayout
} = require("@nodegui/nodegui");

const win = new QMainWindow();

const centralWidget = new QWidget();
centralWidget.setObjectName("myroot");
const rootLayout = new FlexLayout();
centralWidget.setLayout(rootLayout);

const label = new QLabel();
label.setInlineStyle("font-size: 16px; font-weight: bold;");
label.setText("Hello World");

rootLayout.addWidget(label);
win.setCentralWidget(centralWidget);
win.setStyleSheet(
  `
    #myroot {
      background-color: #009688;
    }
  `
);
win.show();

global.win = win;