Ctrl +鼠标左键单击事件捕获Qt

时间:2017-02-15 16:12:21

标签: c++ qt

如何在Qt小部件中获取componentDidMount() { this.props.actions.A().then(result => { this.setState({ a: result }); }); } 事件。我可以从Ctrl+Left mouse click获取关键事件,并从QObject::keyPressEvent()鼠标点击。但是我需要在同一个函数中捕获它们。有人可以给出一些指向正确方向的指针。感谢。

3 个答案:

答案 0 :(得分:2)

您可以尝试使用其他变量,例如:

private:
    bool ctrlIsPressed = false;

protected:
    void keyPressEvent(QKeyEvent *event) 
    { 
        if( event->key() == Qt::Key_Control ) 
           ctrlIsPressed = true; 
    }
    void keyReleaseEvent(QKeyEvent *event)
    { 
        if( event->key() == Qt::Key_Control ) 
           ctrlIsPressed = false; 
    }

    void mousePressEvent()
    {
        if( ctrlIsPressed )
            // ... Your code
    }

答案 1 :(得分:1)

您可以调用QMouseEvent::modifiers()来检查它是否返回值Qt::ControlModifier

答案 2 :(得分:0)

查看此Stackoverflow.com问题。我认为这正是你遇到的问题。

How to detect the modifier key on mouse click in Qt