We do not receive touch inputs(eg. touch begin, touch update)



  • Hi.. I really hope you can help me. So thanks in advance.

    I have a problem about receiving touch inputs like the QEvent::TouchBegin, QEvent::TouchUpdate, or QEvent::TouchEnd. Important, we use QT 4.8.4 because we work on some others code, which we could not update to QT5

    my program is using Qmainwindow, and my event filter is receiving every other inputcode, like gesture(code=197/198), and mouse hover(129).
    So in short how do i make my program receive the touch inputs instead or as well.
    It is like my event filter is filtering touch events out, or the TouchEvents can't go through layers, because if i remove all GUI(only have mainwindow left) i do receive the touch inputs i want, and when I change centralwidget, and add a new ui element / widget i can't receive the touch inputs.

    If you need any information to answer this, just ask please.

    My code look like this:
    my placeholdercopyright.cpp file
    @placeholdercopyright::placeholdercopyright(QWidget *parent, Qt::WFlags flags)
    : QMainWindow(parent, flags)
    {
    //parent->setAttribute(Qt::WA_AcceptTouchEvents);
    //parent->setAttribute(Qt::WA_StaticContents);

    qDebug() << "LS";
    ui.setupUi(this); //If i disable line 171 to end in ui file (see bottom) then my touch
    //inputs work, but i do not have any gui left. Of cause i need to
    //outcomment the lines in this function to make the program run, so i
    //do not use the installeventfilter()

    this->installEventFilter(this);
    
    ui.scrollArea_2->setWidget(ui.imageLabel_ImgShow);
    ui.imageLabel_ImgShow->installEventFilter(this);
    
    ui.scrollArea_3->setBackgroundRole(QPalette::Light);
    ui.scrollArea_3->setWidget(ui.imageLabel_CandidateImgs);
    ui.imageLabel_CandidateImgs->installEventFilter(this);
        ui.scrollArea_p->setBackgroundRole(QPalette::Light);
    ui.scrollArea_p->setWidget(ui.imageLabel_Palette);
    
    ui.imageLabel_Palette->installEventFilter(this);
    
    ui.imageLabel_StrokeColor->installEventFilter(this);
    ui.scrollArea_2->horizontalScrollBar()->installEventFilter(this);
    ui.scrollArea_2->verticalScrollBar()->installEventFilter(this);
    CandidateWindowSwitch(false);
    m_methodType = Brush;
    m_crtColorIdx = 0;
    m_zoomCoef = 1.0;
    
    ui.dockWidget_Palette->hide();
    m_appName = "Lazy Selection";
    MethodBrush();
    PrepareStrokeColor();
    
    m_crtStrokeColor = cv::Scalar(255, 147, 94);
    m_prevStrokeColor = m_crtStrokeColor;
    StoreStrokeColor(m_crtStrokeColor);
    InitializeData();
    m_removeColorMode = false;
    
    setAttribute(Qt::WA_AcceptTouchEvents);
    setAttribute(Qt::WA_StaticContents);
    

    }

    bool LazySelection::eventFilter(QObject* watched, QEvent* e)
    {
    EventKeyboard(watched, e);

    if(watched == ui.imageLabel_ImgShow)
    {
        if (!m_lazySelectionAlg.m_imgShow.data)
        {
            return QObject::eventFilter(watched, e);
        }
        //std::cout << "EventImgShow" << std::endl;
        switch (m_methodType)
        {
        case Brush:
            EventImgShowBrush(e);
            break;
        case SingleClick:
            break;
        case Lasso:
            EventImgShowLasso(e);
            break;
        }
    }
    else if (watched == ui.imageLabel_CandidateImgs)
    {
        if (!m_cvImgCandidate.data)
        {
            return QObject::eventFilter(watched, e);
        }
        //std::cout << "EventImgCandidate" << std::endl;
        EventImgCandidate(e);
    }
    else if (watched == ui.scrollArea_2->verticalScrollBar() || watched == ui.scrollArea_2->horizontalScrollBar())
    {
        const QMouseEvent* const me = static_cast<const QMouseEvent*>(e);
        if(e->type() == QEvent::MouseButtonPress)
        {
            CandidateWindowSwitch(false);
        }
    }
    //std::cout << watched << std::endl;
    return QObject::eventFilter(watched, e);
    

    }

    bool placeholdercopyright::event(QEvent *e)
    {
    //qDebug() << "oh Hi";
    if(e->type()<194 ||e->type()>196){
    }
    else{qDebug() << e->type();}
    //TouchThread(event);
    switch (e->type()) {
    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
    {
    // qDebug() << "Really?";
    //e->accept();
    QListQTouchEvent::TouchPoint touchPoints = static_cast<QTouchEvent *>(e)->touchPoints();
    foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints) {
    switch (touchPoint.state()) {
    case Qt::TouchPointStationary:
    // don't do anything if this touch point hasn't move
    continue;
    default:
    {
    }
    break;
    }
    }
    break;
    }
    default:
    return QWidget::event(e);
    }
    return true;
    }

    // This is UI file
    void setupUi(QMainWindow *LazySelectionClass)
    {
    if (LazySelectionClass->objectName().isEmpty())
    LazySelectionClass->setObjectName(QString::fromUtf8("LazySelectionClass"));
    LazySelectionClass->setWindowModality(Qt::ApplicationModal);
    LazySelectionClass->resize(1060, 701);
    QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
    sizePolicy.setHorizontalStretch(140);
    .....
    imageLabel_CandidateImgs = new QLabel(centralWidget);
    imageLabel_CandidateImgs->setObjectName(QString::fromUtf8("imageLabel_CandidateImgs"));
    imageLabel_CandidateImgs->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop);

        gridLayout_2->addWidget(imageLabel_CandidateImgs, 5, 0, 1, 1);
    

    line 171 LazySelectionClass->setCentralWidget(centralWidget);
    menuBar = new QMenuBar(LazySelectionClass);
    menuBar->setObjectName(QString::fromUtf8("menuBar"));
    menuBar->setGeometry(QRect(0, 0, 1060, 21));

    .....@

    Best regards,
    Simon



  • We have solved the problem.

    The solution was to find the outer layer, and in the correct layer add: setAttribute(Qt::WA_AcceptTouchEvents);
    setAttribute(Qt::WA_StaticContents);

    The problem for us was that we added it in the start to the mainwindow, but we were adding widgets on top of it. We did not notice the error, at first but as soon we added it to the most top layer, it worked.



  • Hi Raistlin,

    I have been reading your post with great interest, as your problems is very similar to mine. I am using Qt5.4 but that is also only difference.

    Are you still at Qt4 or did you move to Qt5?

    Can we share some advice here?

    Henrik


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.