QAxWidget 类

QAxWidget 类是 QWidget 用于包裹 ActiveX 控件。 更多...

头: #include <QAxWidget>
qmake: QT += axcontainer
继承: QWidget and QAxBase

公共函数

QAxWidget (QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags())
QAxWidget (const QString & c , QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags())
QAxWidget (IUnknown * iface , QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags())
~QAxWidget ()
virtual QAxAggregated * createAggregate ()
bool doVerb (const QString & verb )

重实现公共函数

virtual void clear ()
virtual QSize minimumSizeHint () const
virtual QSize sizeHint () const

保护函数

virtual bool createHostWindow (bool initialized )
bool createHostWindow (bool initialized , const QByteArray & data )
virtual bool translateKeyEvent (int message , int keycode ) const

重实现保护函数

virtual void changeEvent (QEvent * e )
virtual void connectNotify (const QMetaMethod & signal )
virtual bool initialize (IUnknown ** ptr )
virtual void resizeEvent ( QResizeEvent * )

额外继承成员

详细描述

QAxWidget 类是 QWidget 用于包裹 ActiveX 控件。

A QAxWidget 可以被实例化成空对象,采用它应包裹的 ActiveX 控件名称,或采用指向 ActiveX 控件的现有接口指针。ActiveX 控件的特性、方法及事件仅使用 QAxBase 支持数据类型,变为可用的 Qt 特性、槽及信号。基类 QAxBase 提供 API 以直接访问 ActiveX 透过 IUnknown 指针。

QAxWidget QWidget 且主要可以这样使用,如,可以按 Widget 层次结构和布局组织它,或充当事件过滤器。标准 Widget 特性,如 enabled 是支持的,但从属 ActiveX 控件以实现支持环境特性 (如:调色板或字体)。 QAxWidget 会试着提供必要提示。

不管怎样,无法重实现特定 Qt 事件处理程序像 mousePressEvent or keyPressEvent 并期望能可靠调用它们。嵌入式控件覆盖 QAxWidget 完全,且通常用于处理用户界面本身。使用特定控件 API (即:监听控件的信号),或使用标准 COM 技术 (像窗口过程子类化)。

QAxWidget 还继承了其 ActiveX 相关的大部分功能从 QAxBase ,尤其 dynamicCall () 和 querySubObject ().

警告: 可以子类化 QAxWidget ,但无法使用 Q_OBJECT 宏在子类中 (不会编译生成的 moc 文件),所以,无法进一步添加信号、槽或特性。此局限性是由在运行时,生成的元对象信息造成的。要解决此问题,聚合 QAxWidget 作为成员对于 QObject 子类。

另请参阅 QAxBase , QAxObject , QAxScript ,和 ActiveQt 框架 .

成员函数文档编制

QAxWidget:: QAxWidget ( QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags())

创建空 QAxWidget 小部件并传播 parent and f QWidget 构造函数。要初始化控件,调用 setControl ().

QAxWidget:: QAxWidget (const QString & c , QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags())

创建 QAxWidget 小部件并初始化 ActiveX 控件 c . parent and f 被传播给 QWidget 构造函数。

另请参阅 setControl ().

QAxWidget:: QAxWidget ( IUnknown * iface , QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags())

创建 QAxWidget 包裹引用 COM 对象通过 iface . parent and f 被传播给 QWidget 构造函数。

QAxWidget:: ~QAxWidget ()

关闭 ActiveX 控件并销毁 QAxWidget 小部件,清理所有分配资源。

另请参阅 clear ().

[virtual protected] void QAxWidget:: changeEvent ( QEvent * e )

重实现自 QWidget::changeEvent ().

[virtual] void QAxWidget:: clear ()

重实现自 QAxBase::clear ().

关闭 ActiveX 控件。

[virtual protected] void QAxWidget:: connectNotify (const QMetaMethod & signal )

重实现自 QObject::connectNotify ().

[virtual] QAxAggregated *QAxWidget:: createAggregate ()

Reimplement this function when you want to implement additional COM interfaces for the client site of the ActiveX control, or when you want to provide alternative implementations of COM interfaces. Return a new object of a QAxAggregated 子类。

默认实现返回 null 指针。

[virtual protected] bool QAxWidget:: createHostWindow ( bool initialized )

Creates the client site for the ActiveX control, and returns true if the control could be embedded successfully, otherwise returns false. If initialized is true the control has already been initialized.

此函数被调用通过 initialize (). If you reimplement initialize to customize the actual control instantiation, call this function in your reimplementation to have the control embedded by the default client side. Creates the client site for the ActiveX control, and returns true if the control could be embedded successfully, otherwise returns false.

[protected] bool QAxWidget:: createHostWindow ( bool initialized , const QByteArray & data )

Creates the client site for the ActiveX control, and returns true if the control could be embedded successfully, otherwise returns false. If initialized is false the control will be initialized using the data . The control will be initialized through either IPersistStreamInit or IPersistStorage interface.

If the control needs to be initialized using custom data, call this function in your reimplementation of initialize (). This function is not called by the default implementation of initialize ().

该函数在 Qt 4.4 引入。

bool QAxWidget:: doVerb (const QString & verb )

Requests the ActiveX control to perform the action verb . The possible verbs are returned by verbs ().

The function returns true if the object could perform the action, otherwise returns false.

该函数在 Qt 4.1 引入。

[virtual protected] bool QAxWidget:: initialize ( IUnknown ** ptr )

重实现自 QAxBase::initialize ().

调用 QAxBase::initialize ( ptr ), and embeds the control in this widget by calling createHostWindow (false) if successful.

To initialize the control before it is activated, reimplement this function and add your initialization code before you call createHostWindow (true)。

该函数在 Qt 4.2 引入。

[virtual] QSize QAxWidget:: minimumSizeHint () const

重实现自 QWidget::minimumSizeHint ().

[virtual protected] void QAxWidget:: resizeEvent ( QResizeEvent * )

重实现自 QWidget::resizeEvent ().

[virtual] QSize QAxWidget:: sizeHint () const

重实现自 QWidget::sizeHint ().

[virtual protected] bool QAxWidget:: translateKeyEvent ( int message , int keycode ) const

Reimplement this function to pass certain key events to the ActiveX control. message is the Window message identifier specifying the message type (ie. WM_KEYDOWN), and keycode is the virtual keycode (ie. VK_TAB).

If the function returns true the key event is passed on to the ActiveX control, which then either processes the event or passes the event on to Qt.

If the function returns false the processing of the key event is ignored by ActiveQt , ie. the ActiveX control might handle it or not.

The default implementation returns true for the following cases:

WM_SYSKEYDOWN WM_SYSKEYUP WM_KEYDOWN
All keycodes VK_MENU VK_TAB, VK_DELETE and all non-arrow-keys in combination with VK_SHIFT, VK_CONTROL or VK_MENU

This table is the result of experimenting with popular ActiveX controls, ie. Internet Explorer and Microsoft Office applications, but for some controls it might require modification.