Attention: употреблять только в смеси с Qt Script Bindings Generator и только в другом виджете. Не создавать как отдельное окно.// Created by trolls instead of __qt_sender__
Function.prototype.bind = function() {
var func = this;
var thisObject = arguments[0];
var args = Array.prototype.slice.call(arguments, 1);
return function() {
return func.apply(thisObject, args);
};
};
NumPad = function(parent)
{
QWidget.call(this, parent);
this.windowTitle = qsTr("NumPad");
this.focusPolicy = Qt.NoFocus;
this.setWindowFlags(Qt.WindowStaysOnTopHint);
this.setAttribute(Qt.WA_ShowWithoutActivating, true);
this.gridlayout = new QGridLayout(this);
this.gridlayout.horizontalSpacing = 0;
this.gridlayout.verticalSpacing = 0;
this.gridlayout.spacing = 0;
this.gridlayout.setContentsMargins(0,0,0,0);
for (var i = 9; i >= 0; --i) {
this["button" + i] = new QToolButton(this);
this["button" + i].objectName = "button" + i;
this["button" + i].text = i;
this["button" + i].autoRepeat = true;
this["button" + i].enabled = true;
var boldFont = new QFont();
boldFont.setBold(true);
boldFont.setPixelSize(12);
this["button" + i].font = boldFont;
this["button" + i].minimumSize = new QSize(42, 42);
this["button" + i].focusPolicy = Qt.NoFocus;
this.gridlayout.addWidget(this["button" + i], Math.floor( Math.abs(i - 9) / 3), Math.abs(i?(i - 1):i)%3, 0);
this["button" + i].clicked.connect(this.digitClicked.bind(this, i));
//print (this["button" + i].objectName + " " + Math.floor( Math.abs(i - 9) / 3)+ " " + Math.abs(i?(i - 1):i)%3);
}
};
NumPad.prototype = new QWidget();
NumPad.prototype.digitClicked = function(digitValue)
{
QCoreApplication.sendEvent(QApplication.focusWidget()
, new QKeyEvent(QEvent.KeyPress, Qt["Key_"+digitValue]
, Qt.NoModifier, "" + digitValue, true, 1));
QCoreApplication.sendEvent(QApplication.focusWidget()
, new QKeyEvent(QEvent.KeyRelease, Qt["Key_"+digitValue]
, Qt.NoModifier, "" + digitValue, true, 1));
};