I have a Qt 6.2 Application (Windows/Mac) using QGraphicsScene and want to use 2 fingers on the touch pad of my laptop for panning - as many other applications do.
Zooming in/out works fine, but using 2 fingers for panning always results in zoom out.
I found a number of questions and some fragmentary samples. But no half way complete example:
- Finger Scrolling in QGraphicsView in QT?
- https://forum.qt.io/topic/119221/how-to-listen-to-qtouchevent-originating-from-a-precision-touch-pad
- https://doc.qt.io/qt-5/gestures-overview.html
What is the right way to do this?
What i tried so far (on Windows):
1)
MyGraphicsView::MyGraphicsView(...) : QGraphicsView()
{
viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
...
bool MyGraphicsView::viewportEvent ( QEvent * event )
{
switch (event->type())
{
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
{
// never called
}
MyDocWin::MyDocWin(...) : CMDIAppDocWin(),
{
setAttribute(Qt::WA_AcceptTouchEvents);
...
bool MyDocWin::event(QEvent *event)
{
switch (event->type())
{
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
{
// never called
}
...
std::vector<Qt::GestureType> sgGestureTypes = {Qt::TapGesture, Qt::TapAndHoldGesture,Qt::PanGesture ,Qt::PinchGesture ,Qt::SwipeGesture };
MyGraphicsView::MyGraphicsView(...) : QGraphicsView()
{
for(Qt::GestureType gesture : sgGestureTypes)
grabGesture(gesture);
...
bool MyGraphicsView::event(QEvent *event)
{
switch (event->type())
{
case QEvent::Gesture:
case QEvent::NativeGesture:
// never called
MyDocWin::MyDocWin(...) : CMDIAppDocWin(),
{
for (Qt::GestureType gesture : sgGestureTypes)
grabGesture(gesture);
...
bool MyDocWin::event(QEvent *event)
{
switch (event->type())
{
case QEvent::Gesture:
case QEvent::NativeGesture:
// never called