PDA

View Full Version : overridden QAxWidget::translateKeyEvent(int message, int keycode) not being called



Bing
9th May 2011, 20:39
I use QAxWidget to wrap an ActiveX control, since the container QWidget needs to customize the KeyPressEvent, so I have inherited from QAxWidget and overridden translateKeyEvent(int message, int keycode), but this function never called. here is the codes:

class CXXXAxWidget : public QAxWidget
{
public:
CXXXAxWidget(QWidget* parent = 0, Qt::WindowFlags f = 0)
: QAxWidget(parent, f)
{
}
protected:
virtual bool translateKeyEvent(int message, int keycode) const;
};

bool CXXXAxWidget::translateKeyEvent(int message, int keycode) const
{
//log

if (message == WM_KEYDOWN)
return true;
else
return QAxWidget::translateKeyEvent(message, keycode);
}

d_stranz
10th May 2011, 04:33
Do you see any events for your ActiveX control? Like mouse events, for example? May be you need to enable the CXXXAxWidget (myWidget->setEnabled( true ))?

ChrisW67
10th May 2011, 05:23
Please us
tags around code.

From the QAxWidget docs:


However, you cannot reimplement Qt-specific event handlers like mousePressEvent or keyPressEvent and expect them to be called reliably. The embedded control covers the QAxWidget completely, and usually handles the user interface itself. Use control-specific APIs (i.e. listen to the signals of the control), or use standard COM techniques like window procedure subclassing.


A version of same question has been asked in the recent past:
http://www.qtcentre.org/threads/40964-handling-events-of-Acrobat-Activex-control-Embedded-in-QAxWidget?highlight=qaxwidget

Bing
11th May 2011, 17:10
ChrisW67, thanks for the help, I did read the document and I know the Qt event might not be reliable to be called. but right now my question is the QAxWidget::translateKeyEvent(...) should be called if we override it, right? but I could not see it is called by tracing the program. any advise, thanks in advance.

ChrisW67
12th May 2011, 01:07
Yes, given that it is part of QAxWidget and not the underlying QWidget interface, I guess it should. Your declaration seems sound, ie. correct signature.

Is the wrapped control common? Could you post a small compilable example that doesn't work?