16,816
社区成员




#ifndef TESTPLUGIN_H
#define TESTPLUGIN_H
#include "ui_testplugin.h"
class CTestPlugin : public QDialog,public Ui_testplugin
{
Q_OBJECT
public:
CTestPlugin(QWidget* = 0);
//~CTestPlugin();
private:
virtual void keyPressEvent(QKeyEvent* k);
};
#endif // TESTPLUGIN_H
#include <stdio.h>
#include <QtGui/QtGui>
#include "testplugin.h"
CTestPlugin::CTestPlugin(QWidget* parent) : QDialog(parent)
{
setupUi(this);
qDebug("Enter CTestPlugin() by zzf!");
//printf("Enter CTestPlugin()!\n");
}
void CTestPlugin::keyPressEvent(QKeyEvent *k)
{
if(k->key() == Qt::Key_1)
//printf("Key 1 tested!\n");
qDebug("Key 1 tested!\n");
else if(k->key() == Qt::Key_2)
//printf("Key 2 tested!\n");
qDebug("Key 2 tested!\n");
else
//printf("other keys tested!\n");
qDebug("other keys tested!\n");
}
#include <QtGui/QApplication>
#include <QtCore/QTextCodec>
#include "testplugin.h"
int main(int argc ,char* argv[])
{
QCoreApplication::addLibraryPath("/usr/lib/plugins");
QApplication app(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
CTestPlugin plugin;
plugin.show();
return app.exec();
}
bool Main_Window::event( QEvent * e )
{
if(e->type () == QEvent::KeyPress){
QKeyEvent *ke=(QKeyEvent *)e;
if(ke->key() == Qt::Key_Enter){
return true;
}
return QWidget::event(e);
}
else
return QWidget::event(e);
}