#include <QtGui>
{
Q_OBJECT
public:
setLayout(layout);
// Organise some fake keyboard activity
connect(timer, SIGNAL(timeout()), SLOT(fakeKeyPress()));
timer->setInterval(500);
timer->start();
}
private slots:
void fakeKeyPress() {
if (focussed) {
}
}
};
int main(int argc, char **argv)
{
Window w;
w.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
class Window: public QWidget
{
Q_OBJECT
public:
explicit Window(QWidget *p = 0): QWidget(p) {
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(new QLineEdit());
layout->addWidget(new QLineEdit());
setLayout(layout);
// Organise some fake keyboard activity
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), SLOT(fakeKeyPress()));
timer->setInterval(500);
timer->start();
}
private slots:
void fakeKeyPress() {
QWidget *focussed = QApplication::focusWidget();
if (focussed) {
QKeyEvent press(QEvent::KeyPress, Qt::Key_1, Qt::NoModifier, "1");
QApplication::sendEvent(focussed, &press);
QKeyEvent release(QEvent::KeyRelease, Qt::Key_1, Qt::NoModifier, "1");
QApplication::sendEvent(focussed, &release);
}
}
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
Window w;
w.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks