QAxWidget 类

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

头: #include <QAxWidget>
CMake: find_package(Qt6 REQUIRED COMPONENTS AxContainer)
target_link_libraries(mytarget PRIVATE Qt6::AxContainer)
qmake: QT += axcontainer
继承: QAxBaseWidget and QAxBase

公共函数

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

重实现公共函数

virtual QSize minimumSizeHint () const override
virtual void resetControl () override
virtual QSize sizeHint () const override

保护函数

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 ) override
virtual void connectNotify (const QMetaMethod & signal ) override
virtual bool initialize (IUnknown ** ptr ) override
virtual void resizeEvent (QResizeEvent *) override

详细描述

A QAxWidget can be instantiated as an empty object, with the name of the ActiveX control it should wrap, or with an existing interface pointer to the ActiveX control. The ActiveX control's properties, methods and events which only use QAxBase 支持数据类型,变为可用 Qt 特性、槽及信号。基类 QAxBase 提供 API 以直接访问 ActiveX 透过 IUnknown 指针。

QAxWidget is a QWidget 且主要可以这样使用,如,可以按 Widget 层次结构和布局组织它,或充当事件过滤器。标准 Widget 特性,如 enabled are supported, but it depends on the ActiveX control to implement support for ambient properties like e.g. palette or font. QAxWidget tries to provide the necessary hints.

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.

QAxWidget also inherits most of its ActiveX-related functionality from QAxBase ,尤其 dynamicCall () 和 querySubObject ().

警告: 可以子类 QAxWidget,但不可以使用 Q_OBJECT macro in the subclass (the generated moc-file will not compile), so you cannot add further signals, slots or properties. This limitation is due to the metaobject information generated in runtime. To work around this problem, aggregate the QAxWidget as a member of the QObject 子类。

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

成员函数文档编制

[explicit] QAxWidget:: QAxWidget ( QWidget * parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags())

Creates an empty QAxWidget widget and propagates parent and f QWidget 构造函数。要初始化控件,调用 setControl ().

[explicit] QAxWidget:: QAxWidget (const QString & c , QWidget * parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags())

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

另请参阅 setControl ().

[explicit] QAxWidget:: QAxWidget ( IUnknown * iface , QWidget * parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags())

Creates a QAxWidget that wraps the COM object referenced by iface . parent and f 被传播给 QWidget 构造函数。

[override virtual noexcept] QAxWidget:: ~QAxWidget ()

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

另请参阅 clear ().

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

重实现: QWidget::changeEvent (QEvent *event).

void QAxWidget:: clear ()

关闭 ActiveX 控件。

另请参阅 resetControl ().

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

重实现: QObject::connectNotify (const QMetaMethod &signal).

[virtual] QAxAggregated *QAxWidget:: createAggregate ()

重实现此函数,当想为 ActiveX 控件客户端站点实现其它 COM 接口时,或者当想要提供 COM 接口的替代实现时。返回新对象为 QAxAggregated 子类。

默认实现返回 null 指针。

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

创建 ActiveX 控件客户端站点,并返回 true 若可以成功嵌入控件,否则返回 false。若 initialized 为 true 控件已初始化。

此函数被调用通过 initialize ()。若重实现初始化以定制实际控件的实例化,在重实现中调用此函数可以让客户端侧默认嵌入控件。创建 ActiveX 控件客户端站点,并返回 true 若可以成功嵌入控件,否则返回 false。

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

创建 ActiveX 控件客户端站点,并返回 true 若可以成功嵌入控件,否则返回 false。若 initialized 为 false 会初始化控件使用 data 。将透过 IPersistStreamInit 或 IPersistStorage 接口初始化控件。

若需要使用自定义数据初始化控件,调用此函数在重实现的 initialize ()。不会调用此函数由默认实现的 initialize ().

bool QAxWidget:: doVerb (const QString & verb )

请求 ActiveX 控制以履行动作 verb 。可能的 verb 的返回是通过 verbs ().

函数返回 true 若对象能履行动作,否则返回 false。

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

重实现: QAxBase::initialize (IUnknown **ptr).

调用 QAxBase::initialize ( ptr ),并嵌入控件在此 Widget 中通过调用 createHostWindow (false) 若成功。

为在激活前初始化控件,重实现此函数并添加初始化代码先于调用 createHostWindow (true)。

返回 true 当成功时, false 否则。

[override virtual] QSize QAxWidget:: minimumSizeHint () const

重实现访问函数为特性: QWidget::minimumSizeHint .

[override virtual] void QAxWidget:: resetControl ()

重实现: QAxObjectInterface::resetControl ().

关闭 ActiveX 控件。

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

重实现: QWidget::resizeEvent (QResizeEvent *event).

[override virtual] QSize QAxWidget:: sizeHint () const

重实现访问函数为特性: QWidget::sizeHint .

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

重实现此函数,以将某些关键事件传递给 ActiveX 控件。 message 是指定消息类型的窗口消息标识符 (即 WM_KEYDOWN),和 keycode 是虚拟键码 (即 VK_TAB)。

若函数返回 true,将键事件传递给 ActiveX 控件,然后处理事件或将事件传递给 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.

以下情况默认实现返回 true:

WM_SYSKEYDOWN WM_SYSKEYUP WM_KEYDOWN
所有键码 VK_MENU VK_TAB、VK_DELETE 和所有非方向键组合 VK_SHIFT、VK_CONTROL 或 VK_MENU

此表格是对流行 ActiveX 控件 (即 Internet Explorer 和 Microsoft Office 应用程序) 的实验结果,但对于某些控件,可能要求修改。