Keypress event catches only en_us clicks, however another class catches en/russian keypresses !!! why?



  • Hello guys,

    I am in a difficult situation .. An error and I don't know where. I have 2 classes, one catches keypresses in any layout (english/german/french/russian ... etc) (this is the keygrabber class) and one catches keypresses only in the en layout (this is the practise class) although both are mostly similar.

    Can any body figure where is the difference between them?

    Practise.h
    @
    #ifndef PRACTISING_H
    #define PRACTISING_H

    #include <QKeyEvent>
    #include <QWidget>

    namespace Ui {
    class practising;
    }

    class practising : public QWidget
    {
    Q_OBJECT

    public:
    practising(QWidget *parent = 0);
    ~practising();

    private slots:

    protected:
    void keyPressEvent(QKeyEvent *event);
    void keyReleaseEvent(QKeyEvent *event);
    void closeEvent(QCloseEvent *event); //3

    private:
    Ui::practising *ui;
    Highlighter *highlighter;
    };
    #endif // PRACTISING_H
    @

    Practise.cpp
    @
    #include "practising.h"
    #include "ui_practising.h"
    #include <QGraphicsScene>
    #include <QGraphicsView>
    #include <QLocale>
    #include <QString>
    #include <QDebug>
    #include <QtGui>
    #include <QtCore>
    #include <QTranslator>
    #include "highlighter.h"
    #include <QKeyEvent>
    #include <QRegExp>
    #include "keygrabber.h"

    // Setting
    QColor BlackboardColor = Qt::gray;

    int fontsize = 35;
    QString fontfamily="Courier";

    //

    int PractiseLessonNumber;
    int MaxPractiseLessons=33; //Maximum number of lessons. To increase it, change value here and see lessons::loadlessontext function
    QString PractiseLessonLable ="Practis Lesson Number";

    practising::practising(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::practising)
    {

    ui->setupUi(this);
    
    QLocale t=QApplication::keyboardInputLocale ();
    qDebug() << "input locale" << t;
    
    // Check language direction. If RTL swap arrows in the next and previous buttons
    //qDebug() << "language direction is " << qApp->layoutDirection();
    if (qApp->layoutDirection()==1) // RTL layout
    {
        QPixmap pixmap(":/images/icons/navigate-left-icon.png");
        QIcon ButtonIcon(pixmap);
        QPixmap pixmap1(":/images/icons/navigate-right-icon.png");
        QIcon ButtonIcon1(pixmap1);
        ui->previous_Btn->setIcon(ButtonIcon1);
        ui->next_Btn->setIcon(ButtonIcon);
    }
    
    
    
    qDebug() << "start key grabber";
    
    keygrabber *blub = new keygrabber();
    blub->show();
    

    }

    @

    keygrabber.h
    @
    #ifndef KEYGRABBER_H
    #define KEYGRABBER_H

    #include <QWidget>
    #include <QKeyEvent>

    class keygrabber : public QWidget
    {
    public:
    keygrabber(QWidget *parent = 0);

    protected:
        virtual void keyPressEvent(QKeyEvent *event);
        virtual void keyReleaseEvent(QKeyEvent *event);
    

    };

    #endif

    @

    keygrabber.cpp
    @
    #include "keygrabber.h"
    #include <QDebug>

    keygrabber::keygrabber(QWidget *parent)
    : QWidget(parent)
    {
    //for (int i=0; i<2; i++){taste_pressed[i] = -1;}
    }

    void keygrabber::keyPressEvent(QKeyEvent *event)
    {

    qDebug() << event;
    return;
    

    }

    void keygrabber::keyReleaseEvent(QKeyEvent *event)//traegt die zeichen wieder aus dem array taste_pressed[] aus
    {

    }

    @

    Why does keygrabber accept all keypresses in all layouts, but practise not?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.