nodeguy/website/docs/api/synopsis.md
Atul R eca218ac79
Adds new doc site (#124)
* Adds base template for new docs site

* Adds Apis to docs

* add some css from rn

* Fix right side sidebar functionality

* Basic docs

* adds old docs

* Cleans up unnecessary files

* Chane links

* Adds docusaurus v2

* Styling fixes

* adds wip and new assets

* adds code image

* Add FAQ link

* Adds analytics

* adds cname

* cleanup blogs
2019-09-29 20:14:35 +02:00

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;