[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    META Key working in Qt2.3
From:       Ellis Whitehead <lists () ellisw ! net>
Date:       2001-05-09 20:24:02
[Download RAW message or body]

Following up on my post about a new keyboard schema:

A couple people said that the META isn't supported in Qt2.x.  Withfour lines 
of code (2 to qapplication_x11.cpp and 2 to qnamespace.h) and a little test 
app, and as far as i can tell, it works fine.

If anyone know of hidden problems here, please let me know.  I'm going to 
start checking out how to integrate this into KGlobalAccel and family... (any 
pointers here could be useful too <grin>)

Thanks!
Ellis

qnamespace.h: 
in enum Buttonstate:
	AltButton	= 0x0020,
+        	MetaButton      = 0x0040,
-	KeyButtonMask	= 0x0038,
+	KeyButtonMask	= 0x0078,       // ellis -- 2001-05-09, was 0x0038

qapplication_x11.cpp
in static int translateButtonState( int s ):	
    	if ( s & Mod1Mask )
		bst |= Qt::AltButton;
+    	if ( s & Mod4Mask )         // ellis -- 2001-05-09
+        		bst |= Qt::MetaButton;  // ellis -- 2001-05-09
	return bst;

test_meta.cpp
#include <qapplication.h>
#include <qlineedit.h>
#include <qevent.h>

class MyWidget : public QLineEdit
{
public:
    MyWidget( QWidget *parent=0, const char *name=0 );
protected:
        virtual void keyPressEvent( QKeyEvent *e );
};

MyWidget::MyWidget( QWidget *parent, const char *name )
        : QLineEdit( parent, name )
{
}

void MyWidget::keyPressEvent( QKeyEvent *e )
{
        QString key, ascii, state;

        key.setNum( e->key(), 16 );
        ascii = e->ascii();
        state.setNum( e->state(), 16 );

        setText( "key: 0x" + key + ", ascii: '" + ascii + "', state: 0x" + 
state );
}

int main( int argc, char **argv )
{
    QApplication a( argc, argv );

    MyWidget w;
    w.setGeometry( 100, 100, 200, 100 );
    a.setMainWidget( &w );
    w.show();
    return a.exec();
}
 
>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic