How do you make the QListWidget swipe



  • I'm trying to figure out Qt under Android. The form is filled with QListWidget, and the usual sensorship is not working.

    So how do you put a wire on?

    Project file.pro:

    QT       += core gui
    

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = AndroidMainWindow
    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui

    CONFIG += mobility
    MOBILITY =

    B .cpp only QListWidget no change

    QListWidget QComboBox

    for( short i = 0; i < 50; i++ )
    {
    QListWidgetItem * item = new QListWidgetItem();
    item->setSizeHint( QSize(0, 70) );
    item->setText( "Элемент списка номер " + QString::number(i) );
    ui->listWidget->addItem( item );
    }



  • First, sensor processing needs to be included with a function http://doc.qt.io/qt-5/qwidget.html#grabGesture :

    QListWidget * my_list = ...
    my_list->grabGesture(Qt::SwipeGesture);
    

    Second option, use class http://doc.qt.io/qt-5/qscroller.html :

    QScroller::grabGesture(my_list, QScroller::LeftMouseButtonGesture);
    

    If QScroller is not comfortable with sensor events http://doc.qt.io/qt-5/qgestureevent.html (example with doc.qt.io):

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

    bool MyWidget::gestureEvent(QGestureEvent *event)
    {
    if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
    swipeTriggered(static_cast<QSwipeGesture *>(swipe));
    else if (QGesture *pan = event->gesture(Qt::PanGesture))
    panTriggered(static_cast<QPanGesture *>(pan));
    if (QGesture *pinch = event->gesture(Qt::PinchGesture))
    pinchTriggered(static_cast<QPinchGesture *>(pinch));

    return true;
    

    }

    http://doc.qt.io/qt-5/gestures-overview.html




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2