nodeguy/src/demo.ts
Pepijn b9ca846835 QMouseEvent() wrapper (#197)
* ADDS initial support for wrapping native events in  QMouseEvent()

only x, y and button are wrapped

* ADDS global coordinates

Cleanup
2019-11-17 08:26:46 +01:00

45 lines
1.3 KiB
TypeScript

import { QMainWindow } from './index';
import { QWidget } from './lib/QtWidgets/QWidget';
import { FlexLayout } from './lib/core/FlexLayout';
import { QLabel, QLabelEvents } from './lib/QtWidgets/QLabel';
import { AlignmentFlag } from './lib/QtEnums';
import { QPixmap } from './lib/QtGui/QPixmap';
import { QMouseEvent } from './lib/QtGui/QEvent/QMouseEvent';
const win = new QMainWindow();
const view = new QWidget();
view.setLayout(new FlexLayout());
view.setStyleSheet(`
flex: 1;
width: '100%';
height: '100%';
`);
const hello = new QLabel();
hello.setText('Hello');
hello.setStyleSheet(`
border: 1px solid blue;
`);
const world = new QLabel();
world.setText('World');
world.addEventListener(QLabelEvents.MouseButtonPress, e => {
const event = new QMouseEvent(e);
console.log('clicked!', event.x(), event.y());
});
world.setStyleSheet(`
border: 1px solid blue;
qproperty-alignment: AlignCenter;
`);
const pixmap = new QPixmap('/Users/atulr/Project/nodegui/nodegui/extras/assets/kitchen.png');
hello.setProperty('pixmap', pixmap);
hello.setProperty('alignment', AlignmentFlag.AlignCenter);
if (view.layout) {
view.layout.addWidget(hello);
view.layout.addWidget(world);
}
win.setCentralWidget(view);
win.show();
(global as any).win = win; // To prevent win from being garbage collected.