QT 5.4 widget touch event
-
Hello,
I am running the broadcast sender widget example and I am trying to enable touch events for the widget.
I have installed tslib library and ran ts_calibrate and ts_test to calibrate and verify the touch screen is working properly which it is.I have set up the environment variables for the tslib which are:
TSLIB_CONFILE=/etc/ts.conf
TSLIB_CALIBFILE=/etc/pointercal
TSLIB_CONSOLEDEVICE=none
TSLIB_tseventtype=INPUT
TSLIB_FBDEVICE=/dev/fb0
TSLIB_TSDEVICE=/dev/input/event0
TSLIB_PLUGINDIR=/usr/lib/tsI have also set up the QT environment variables:
QT_PLUGIN_PATH=/usr/lib/plugins
QT_QPA_FONTDIR=/usr/lib/fonts
QT_QPA_PLATFORM_PLUGIN_PATH=/usr/lib/plugins/platforms
QT_QPA_PLATFORM=linuxfb
QT_QPA_GENERIC_PLUGINS=tslib:/dev/input/event0I went to the constructor for the widget and set the "setAttribute(Qt::WA_AcceptTouchEvents)"
right now I am just trying to see if the touch events are being registered. I set up a mousePressEvent method to see the mouse events which worked fine:
void Sender::mousePressEvent(QMouseEvent *event){ if(event->button() == Qt::LeftButton){ qDebug() << "left mouse click"; } else { //do something } }
when i run the application with the above code and when i click the left mouse button on the widget I see "left mouse click" in the application output so I am trying to do something similar with the touch events and set up an event filter:
void Sender::eventFilter(QTouchEvent *event){ if(event->type() == QTouchEvent::TouchBegin){ qDebug() << "touch event"; } else { //do something } }
however I have yet to see anything on the application output. I have read various other threads looking for a solution but have not been able to find one yet. any help would be appreciated
-
@elliottal
not every touchscreen (actually its driver) produces touch events but only mouse eventsalso on which object did you install the event filter? you should install it on the qApp instance to make sure.
-
in the broadcastsender example I installed the eventFilter on the startButton and quitButton Objects.
startButton->installEventFilter(this) quitButton->installEventFilter(this)
forgive me but I am very new to Qt and am not sure where to install the eventfilter on the qApp instance. How would I go about installing it on the qApp instance?
-
@elliottal said in QT 5.4 widget touch event:
How would I go about installing it on the qApp instance?
qApp->installEventFilter(..);
This way you will filter every events before it is sent to any widget/object.
-
I installed the eventFilter as you suggested and added the following line of code to the constructor
qApp->installEventFilter(this);
I implemented the event filter function as shown below so that I can see any events passed to the app.
bool Sender::eventFilter(QObject *target, QEvent *event){ qDebug() << "event received" << target->metaObject()->className() << event->type(); return false; }
however I am still not seeing anything displayed showing the touch events are being sent to QT and displayed on the application output. Is this not enough to see touch events from the touch screen or should I be able to see touch events displayed with that?
-
@elliottal
as i already stated in my first post.
make sure that it actually sends touch events.
Read the displays datasheet. Most cheap displays mostly simply emulate a mouse. -
@raven-worx
I already did that. In my first post I said that I ran ts_calibrate and ts_test which is a part of the tslib library to verify the touch screen is working. Maybe I'm not understanding you correctly but I figure that would be enough to know that the touch screen is sending touch events. It does just emulate a mouse since it is labeled as HID-MOUSE. I figured that since I know the touch screen is working and does send touch events that I could run the code that I last sent to at least see that the touch events are being passed to QT.
Post 1 of 7