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:
{
Q_OBJECT
public:
CWidget()
{
};
virtual ~CWidget()
{
}
protected:
{
if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier))
{
qDebug() << "strange copy: Ctrl-C";
}
}
}; //
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);
}
}; //
To copy to clipboard, switch view to plain text mode
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 code 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
Here is the project can be compiled using vs2008 + Qt Addin + Qt 4.7.3:
CWidget.zip
Bookmarks