Strange, double-clicking / dragging the mouse will trigger the key event & ldquo; CTRL-C & rdquo;

advertisements

Qt seems to behavior strangely: when mouse double click or dragging on a widget, it will trigger the Ctrl-C key event. Here is my code:

class CWidget: public QWidget
{
    Q_OBJECT

public:
    CWidget()
    {

    };
    virtual ~CWidget()
    {
    }

protected:
    void keyPressEvent ( QKeyEvent * event )
    {
        if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier))
        {
            qDebug() << "strange copy: Ctrl-C";
        }
        QWidget::keyPressEvent(event);
    }
}; //

After the widget is shown, you can perform mouse double click and dragging around on it, and the debug message "strange copy:Ctrl-C" is printed. I have been searching over the internet for two days about this, and found nothing.

Did I use it wrong or it is a bug of Qt?

The code is tested under (vs2008 + Qt Addin + Qt 4.7.3) and (qcreator + Qt 4.7.3 ), xp sp2


You must check:

!event->isAutoRepeat();