Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Qt滑动手势不工作_C++_Qt_Swipe_Gestures - Fatal编程技术网

C++ Qt滑动手势不工作

C++ Qt滑动手势不工作,c++,qt,swipe,gestures,C++,Qt,Swipe,Gestures,我试图在我的小部件中启用滑动手势,但不幸的是,它不起作用。 我遵循了Qt提供的文档和示例 以下是我代码的一部分: MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { grabGesture(Qt::SwipeGesture); } bool MainWindow::event(QEvent *event){ if (event->ty

我试图在我的小部件中启用滑动手势,但不幸的是,它不起作用。 我遵循了Qt提供的文档和示例

以下是我代码的一部分:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    grabGesture(Qt::SwipeGesture);
}

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

bool MainWindow::gestureEvent(QGestureEvent *event){
    if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
        swipeTriggered(static_cast<QSwipeGesture *>(swipe));
    return true;
}

void MainWindow::swipeTriggered(QSwipeGesture *gesture){
    if (gesture->state() == Qt::GestureFinished){
        if (gesture->verticalDirection() == QSwipeGesture::Up)
            goButtomLabel();
        if (gesture->verticalDirection() == QSwipeGesture::Down)
            goUpperLabel();
        update();
    }
}

void MainWindow::goButtomLabel(){
    // does something here
}

void MainWindow::goUpperLabel(){
   // does something here
}
MainWindow::MainWindow(QWidget*父项):
QMainWindow(父级),
用户界面(新用户界面::主窗口)
{
抓取手势(Qt::SwipeGesture);
}
bool主窗口::事件(QEvent*事件){
如果(事件->类型()==QEvent::手势)
返回手势事件(静态施法(事件));
返回QWidget::事件(event);
}
bool主窗口::gestureEvent(QGestureEvent*事件){
如果(Qsignature*swipe=event->signature(Qt::SwipeGesture))
滑动(静态施法(滑动));
返回true;
}
void主窗口::SwipTriggered(QSwipe手势*手势){
如果(手势->状态()==Qt::手势完成){
如果(手势->垂直方向()==QSWIPPORATE::Up)
goButtomLabel();
如果(手势->垂直方向()==QSWIPPORATE::向下)
goUpperLabel();
更新();
}
}
void主窗口::goButtomLabel(){
//这里有什么事吗
}
void主窗口::goUpperLabel(){
//这里有什么事吗
}
有什么问题吗?我忘了什么吗

<>我是QT新手,也是C++初学者,我非常感谢你的帮助。
非常感谢你

你在哪个平台上工作?我在Linux/Ubuntu上使用Qt4,我使用的是多点触摸显示屏。