Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Does QTreeView have TouchEvents or not?



  • I'm trying to port my QWidget based project from Windows to Android
    i have QTreeView and right-mouse-button-menu and i want to make this menu open when i touch this QTreeView on my phone
    i've tried few variants but it still has no reaction when i touch the screen


  • Moderators

    @DrageFabeldyr said in Does QTreeView have TouchEvents or not?:

    i have QTreeView and right-mouse-button-menu and i want to make this menu open when i touch this QTreeView on my phone

    Follow the Image Gestures Example analogous with the QTabAndHoldGesture and open the menu.
    There is no default implementation which does that for you already for touch events.



  • @raven-worx thanx, seems i'm starting to get what i want



  • and if i have two QTreeViews on my widget is it possible to recognize on which one i TapAndHold?
    it seems that it's impossible to do by gesture->position


  • Moderators

    @DrageFabeldyr
    simpliest would be when you subclass QTreeView and handle the gesture events there instead in the container widget. Or is there a reason you are handling the event in the container widget?



  • @raven-worx i've already thought about that
    both my QTreeViews have their models as subclass, so i think it won't be difficult
    the reason.... i just have all right-mouse-button coding for Windows in container widget but it seems i can't use it twice for gestures too, so i think there is no exact reason
    at least, at this moment



  • @raven-worx i'm using "imagegestures" example as basis
    there is in mainwidget.cpp

    void MainWidget::grabGestures(const QList<Qt::GestureType> &gestures)
    {
        imageWidget->grabGestures(gestures);
    }
    

    in my case it was

    void MainWidget::grabGestures(const QList<Qt::GestureType> &gestures)
    {
        containerWidget->grabGestures(gestures);
    }
    

    so now it will be

    void MainWidget::grabGestures(const QList<Qt::GestureType> &gestures)
    {
        containerWidget->firstTreeView->grabGestures(gestures);
        containerWidget->secondTreeView->grabGestures(gestures);
    }
    

    am i right?



  • @raven-worx is there any way to do what i want in conteiner widget, because both treeviews connected to each other: all info showing in second depends on highlighted line in the first like groups and elements



  • solved by checking vertical coordinate of gesture:

        if (gesture->state() == Qt::GestureFinished)
        {
            if ((gesture->position().y() > TreeView2->pos().y()) && (gesture->position().y() < (TreeView2->pos().y() + TreeView2->height())))
            {
                if (!TreeView1->selectionModel()->selectedIndexes().empty()) // you have to select any line in 1 to work with 2
                    slot_TreeView2_menu();
            }
            if ((gesture->position().y() > TreeView1->pos().y()) && (gesture->position().y() < (TreeView1->pos().y() + TreeView1->height())))
            {
                    slot_TreeView1_menu();
            }
        }
    

Log in to reply