Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Widgets Gesture Events - How make TapAndHoldGesture look like double-click event for all children?
QtWS25 Last Chance

Widgets Gesture Events - How make TapAndHoldGesture look like double-click event for all children?

Scheduled Pinned Locked Moved Mobile and Embedded
1 Posts 1 Posters 936 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EdOfTheMountain
    wrote on last edited by
    #1

    Are there any approaches at the QMainWindow level that could emulate a mouse double-click event and propagate down to the children?

    I have a widget app using QStackedWidget containing multiple pages of child widgets. I was hoping to avoid having to add grabgesture code to every widget in my application. For example, the ugly experimental code below allows a TapAndHoldGesture to perform a mouse double-click and call TreeWidget:: itemActivated(). The TapAndHoldGesture works better on small screens where use find it hard to double-click on tiny TreeWidget items.

    Thanks for any advice,

    -Ed

    @
    FormBluetoothDeviceTree::FormBluetoothDeviceTree(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Form),
    m_localDevice(new QBluetoothLocalDevice)
    {
    ui->setupUi(this);
    grabGesture(Qt::TapAndHoldGesture);
    }

    bool FormBluetoothDeviceTree::event(QEvent event)
    {
    if (QEvent::Gesture == event->type())
    {
    return gestureEvent(static_cast<QGestureEvent
    >(event));
    }
    return QWidget::event(event);
    }

    bool FormBluetoothDeviceTree::gestureEvent(QGestureEvent *event)
    {
    qDebug("gestureEvent():");
    if (QGesture *tapAndHold = event->gesture(Qt::TapAndHoldGesture))
    {
    qDebug("TapAndHoldGesture");
    if(tapAndHold->hasHotSpot())
    {
    // The hot-spot is a point in the global coordinate system,
    // use QWidget::mapFromGlobal() or QGestureEvent::mapToGraphicsScene() to get a local hot-spot
    QPoint hotSpotPoint = tapAndHold->hotSpot().toPoint();
    QWidget target = this->childAt(this->mapFromGlobal(hotSpotPoint));
    if(0 == target)
    {
    qDebug() << "Holding: " << "not found";
    }
    else
    {
    qDebug() << "Holding: " << target->objectName();
    if("qt_scrollarea_viewport" == target->objectName())
    {
    qDebug() << "Holding parent: " << target->parent()->objectName();
    if("treeList" == target->parent()->objectName())
    {
    if( 1 <= ui->treeList->selectedItems().count())
    {
    QTreeWidgetItem
    item = ui->treeList->selectedItems().at(0);
    if(0 != item && Qt::GestureFinished == tapAndHold->state())
    {
    // act like user double-clicked item
    ui->treeList->itemActivated(item, 0);
    }
    }
    }
    }
    }
    }
    }
    return true;
    }
    @

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved