Showing posts with label Qt. Show all posts
Showing posts with label Qt. Show all posts

Friday, June 24, 2011

QT keyboard events

I am here to make a quick post. I searched for this at many places but could not get the exact solutions. Every message I could read sounded cryptic.

Scenario:
I want to generate fake keyboard events and send to QWebView class.

Solution:
Extend this class to have slots for signals. Connect it to a signal that can pass an ascii character.

Issue:
Keyboard does not have 'a' and 'A'. It only has an 'A'. That means, I cannot directly send any lower case characters using the event (Which is not correct)

Solution:
The solution is simple. The constructor of QKeyEvent can take QString as one of its argument. The signature is as follows:

QKeyEvent ( Type type, int key, Qt::KeyboardModifiers modifiers, const QString & text = QString(), bool autorep = false, ushort count = 1 )





Even if we don't pass the QString, it will work. However, by passing the QString, we can control exactly what will be displayed.
This is how I create my QKeyEvent:


void MyWebView::rcvKeys(int k)
{

char str[2];
str[0]=k;
str[1]='\0';

QKeyEvent *k=new QKeyEvent(QEvent::KeyPress,k,Qt::NoModifier,QtString(str),false,0)

//-----------Pass it to postevent etc
}
}

Tuesday, March 24, 2009

Qt-4

I started learning this on Fedora 10 machine. The first thing that I noticed is qmake is named qmake-qt4. The following are my learnings yesterday.

1. Qt uses concepts of widgets (Which is very common and hence it was easily understandable)
2. Qt has built in layout classes which can be used to decide how you place your widgets in parent window
3. Qt has an assistant called assistant-qt4. This is used for searching and displaying Qt reference documents.
On F10, I found that assistant-qt4 is not able to search any docs as the docs were not installed. I have started installing them. This rpm is 85MB!
4. Qt works on "signals" and "slots"
5. Signals are the events such as mouse clicks
6. Slots are the functions that will be executed when a signal is received

Monday, March 23, 2009

Qt

For a while I was thinking about making some GUI programs. I have been looking at Java for that. But, for some reason I was not able to get into the details. May be because Java is still a mystery for me. It is only recently I looked at Qt. Since it is cpp, I feel closer to Qt :) I am going to try my luck with Qt. Will keep posting my progress here.

Compiling a Qt app:

0. Ensure that you have qt and qt-devel (yum -y install qt qt-devel)
1. Create a Qt source file first.cpp
2. Create a project with the command
qmake -project
3. Create a makefile
qmake first.pro
4. Make the app
make