Hi
I am trying to implement an application that takes touch alone and ignores mouse events. From the developer doc , I understand that Qt::WA_AcceptTouchEvents has to be enabled for the widget and the event() fn needs to be reimplemented. I have a following code segment to do this. Am i missing something. I am not able to get the touch to work.
---------------------------------------------------------
touch3.h
class Touch3 : public QWidget
{
Q_OBJECT
public:
Touch3(QWidget *parent = 0);
~Touch3();
bool event(QEvent *);
public slots:
void appendText1();
void appendText2();
private:
QTextEdit *displayArea;
QPushButton *helloButton;
QPushButton *worldButton;
QGridLayout *mainLayout;
}
=================================================
main.cpp
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Touch3 w;
w.show();
return a.exec();
}
==================================================
touch3.cpp
Touch3::Touch3(QWidget *parent)
: QWidget(parent)
{
setAttribute(Qt::WA_AcceptTouchEvents);
displayArea = new QTextEdit;
helloButton = new QPushButton;
helloButton->setText(tr("Hello"));
worldButton = new QPushButton;
worldButton->setText(tr("World"));
mainLayout = new QGridLayout;
mainLayout->addWidget(helloButton, 0, 0);
mainLayout->addWidget(worldButton, 0, 1);
mainLayout->addWidget(displayArea, 1, 0, 1, -1);
setLayout(mainLayout);
setWindowTitle(tr("Hello Touch"));
}
bool Touch3::event(QEvent *e)
{
switch(e->type())
{
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
displayArea->append(tr("Touch active"));
break;
case QEvent::MouseButtonPress:
case QEvent::MouseButtonDblClick:
case QEvent::MouseButtonRelease:
case QEvent::MouseMove:
case QEvent::MouseTrackingChange:
e->ignore();
default:
return QWidget::event(e);
}
return true;
}
===================================
Please help in to understand how to get touch working in my application.
Thanks a lot in advance,
Bala

Reply With Quote


