QScrollArea and TouchEvent
Hello,
My problem today is about tactil event on QScrollArea.
My view has:
One ScrollArea which contain some ToolButton
I create my class ScrollArea like this:
Code:
ScrollArea
::ScrollArea(QWidget *parent
){
setAttribute(Qt::WA_AcceptTouchEvents);
}
bool ScrollArea
::event(QEvent* event
) {
switch (event->type()) {
{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
touchPoints.first().setLastPos(touchPoints.first().pos());
}
break;
{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
if(touchPoints.count() == 1 && !touchPoint0.lastPos().isNull() )
{
// determine scale factor
QPointF delta
= touchPoint0.
pos() - touchPoint0.
lastPos() ;
if(touchPoint0.lastPos().x() > touchPoint0.pos().x())//old position is qpoint it remembers last position
this->horizontalScrollBar()->setValue(this->horizontalScrollBar()->value() - delta.x());
if(touchPoint0.lastPos().x() < touchPoint0.pos().x())
this->horizontalScrollBar()->setValue(this->horizontalScrollBar()->value() - delta.x());
if(touchPoint0.lastPos().y() > touchPoint0.pos().y())
this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() - delta.y());
if(touchPoint0.lastPos().y() < touchPoint0.pos().y())
this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() - delta.y());
return true;
}
}break;
default:
break;
}
}
Of course, I have create my class ToolButton to accept touchEvents:
Code:
this->setAttribute(Qt::WA_AcceptTouchEvent);
The scroll works fine if the start of my touch is on the background of ScrollArea. If my first touch begin on ToolButton, the event is not sent to my parent (here ScrollArea).
Someone can help me?
Thanks.
Re: QScrollArea and TouchEvent
Do you want to handle the touch event in the toolbutton? if not then disable the accept touch event, then the event should be propagated to the parent widget (scroll area).
The touch events will go up the list of parents until one of then accepts the event or uses an eventfilter that consumes the event. Be sure to set the parent on the toolbutton!
Re: QScrollArea and TouchEvent
Yes I want handle the event in ToolButon so the event no sent to parent ...
But an handle just for click on the ToolButon.