Two QPushButtons for control car
I'm writing simple mobile application which will be controling small toy car via WIFI.
So there are 4 buttons- Up Down Left Right.
There are pretty common to press two button at once - for example change direction: Up&Right.
The problem is when I Up button is pressed all other are block until the first will be released.
I get stuck.. this is simple problem but on PC application doesn't exist due to we have 'one finger' there.
Is there any solution to force button to be non-blocking?
kolegs last edited by
Did you consider using MultiPointTouchArea in qml?
I think it can be a solution for the problem
I use Qt SDK 1.2.1 and for the first glance I can't see at help: 'MultiPointTouchArea' - I suppose this is be something new. So it might involve a lot of change.
I'm wondering if checking each buttons by using timer would solve the problem...
Salvatello last edited by
I suggest 2 possible choices. Of course I do not know if I'm correct, you have to try them.
the simplest but also the less beautiful. You must create 8 buttons: up, down, right, left, up-right, down-right, down-left, up-left.
the solution is less elegant, but should work fine.
You can use the keyPressEvent (QKeyEvent * s) with the combination of 2 buttons. I'll write an example:
@void Main::keyPressEvent(QKeyEvent *e)
if (e->type() == QEvent::KeyPress)
QKeyEvent keyEvent = static_cast<QKeyEvent>(e);
int keyInt = keyEvent->key(); Qt::KeyboardModifiers modifiers = keyEvent->modifiers(); if(modifiers & Qt::ShiftModifier) keyInt += Qt::SHIFT; if(modifiers & Qt::ControlModifier) keyInt += Qt::CTRL; if(modifiers & Qt::AltModifier) keyInt += Qt::ALT; if(modifiers & Qt::MetaModifier) keyInt += Qt::META; if(keyInt==Qt::ALT+Qt::Key_Q) on_spacePushButton_clicked(); if(keyInt==Qt::ALT+Qt::Key_F10) on_pushButtonEsc_clicked(); if(keyInt==Qt::Key_F1) on_caricoTaglioPushButton_clicked(); if(keyInt==Qt::Key_F2) on_eseguiCADpushButton_clicked();@
of course in my case the two keys are alt + Q or Alt + F10.
You should put your keys.
Yeah, the first idea is must work.
The second probably will not - because I want to grab events from QPushButton (application will work on Nokia 500).
keyPressEvent(QKeyEvent *e) - I suppose will work fine for keyboard buttons.
I'm going to take 8 buttons approach at first.
I believe that QTouchEvent will match to solve fully this issue.
Ildar last edited by
bq. I use Qt SDK 1.2.1
Your Qt version is very old. You can get newer version from "download page":http://qt-project.org/downloads
I have checked new Qt 5.3.2 but itsn't support Symbian Applicastion like Qt SDK 1.2.1 (I can see that there is option for Android). That's the reason why I stick to old version.
I've just checked solution with 8 buttons but unfortunately it will not work as I want.
User will have to press button on a touch screen (for example Left) but he will have to release them before will be able press any other. It is not possible just slide through each 8 buttons without detach finger from touch screen.
andre last edited by
In that case: don't use buttons. Use a single widget of your own on which you register where it is pressed. Use that location to figure out what direction that translates in. I'd probably convert the touch coordinate into polar coordinates, and use a set of ranges for the phi (angle) value. You could base it of a QFrame, for instance.