@nodegui/nodegui
Version:
A cross-platform library to build native desktop apps.
53 lines (52 loc) • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const QMainWindow_1 = require("./lib/QtWidgets/QMainWindow");
const QLabel_1 = require("./lib/QtWidgets/QLabel");
const FlexLayout_1 = require("./lib/core/FlexLayout");
const QWidget_1 = require("./lib/QtWidgets/QWidget");
const QBoxLayout_1 = require("./lib/QtWidgets/QBoxLayout");
const QtEnums_1 = require("./lib/QtEnums");
const QStackedLayout_1 = require("./lib/QtWidgets/QStackedLayout");
const QComboBox_1 = require("./lib/QtWidgets/QComboBox");
// Create main window
const win = new QMainWindow_1.QMainWindow();
win.setWindowTitle('QStackedLayout');
// Create central widget and layout
const centralWidget = new QWidget_1.QWidget();
centralWidget.setObjectName('myroot');
const rootLayout = new QBoxLayout_1.QBoxLayout(QtEnums_1.Direction.TopToBottom);
centralWidget.setLayout(rootLayout);
// Create stacked layout
const stackedLayout = new QStackedLayout_1.QStackedLayout();
// Create pages with labels
const createPage = (text) => {
const page = new QWidget_1.QWidget();
const layout = new FlexLayout_1.FlexLayout();
page.setLayout(layout);
const label = new QLabel_1.QLabel();
label.setText(text);
layout.addWidget(label);
return page;
};
stackedLayout.addWidget(createPage('This is page 1'));
stackedLayout.addWidget(createPage('This is page 2'));
stackedLayout.addWidget(createPage('This is page 3'));
// Create combo box to switch pages
const combobox = new QComboBox_1.QComboBox();
combobox.addItems(['Page 1', 'Page 2', 'Page 3']);
combobox.addEventListener('currentIndexChanged', (index) => stackedLayout.setCurrentIndex(index));
// Add combo box and stacked layout to root layout
rootLayout.addWidget(combobox);
rootLayout.addLayout(stackedLayout);
// Create and update label for current index
const currentIndexLabel = new QLabel_1.QLabel();
currentIndexLabel.setText(`Current Index: ${stackedLayout.currentIndex()}`);
stackedLayout.addEventListener('currentChanged', (index) => {
currentIndexLabel.setText(`Current Index: ${index}`);
});
rootLayout.addWidget(currentIndexLabel);
// Set up and show main window
win.setCentralWidget(centralWidget);
win.setMinimumSize(300, 100);
win.show();
global.win = win;