PDA

View Full Version : How to show MS Word int QWidget ?



luoyes
6th January 2011, 05:39
Hello, I want to show MS Word in QWidget, I 've tried like this:

In a QWidget's constructor:



QString qsFileName( "D:/Test/Test.doc" );

QHBoxLayout *playout = new QHBoxLayout( this );
setLayout( playout );

QAxWidget *pAxWidget = new QAxWidget( this );

playout->addWidget( pAxWidget );
playout->setMargin( 0 );

pAxWidget ->setControl( qsFileName );



Use this method, I can show it in a QWidget, but these menubars and commandbars are hidden.

So I tried to make them visible like this:



QAxObject *pStandard = pAxWidget->querySubObject( "CommandBars( const QVariant & )", "Standard" );
pStandard->dynamicCall( "Enabled", true );
pStandard->dynamicCall( "Visible", true );
QAxObject *pFormatting = pAxWidget->querySubObject( "CommandBars( const QVariant & )", "Formatting" );
pFormatting->dynamicCall( "Enabled", true );
pFormatting->dynamicCall( "Visible", true );


but I still cannot see any commandBar.

Can you help me? Thanks.

wysota
6th January 2011, 11:22
Are you sure those objects have properties Enabled and Visible?

luoyes
7th January 2011, 00:03
Thanks for you attention.
Yes, I'm sure, I found it in the MSDN.
I think the problem is there is no room to show these commandbars.There must be some pannel or something else should be turned on, or use QAxWidget::setControl() with a file name is not a good way.

wysota
7th January 2011, 01:20
What does generateDocumentation() for each of the subobjects return?

luoyes
7th January 2011, 02:21
Returns nothing.

Here is all the code.




QString qsFileName( "D:/Test/Test.doc" );

QHBoxLayout *playout = new QHBoxLayout( this );
setLayout( playout );

m_pAxWidget = new QAxWidget( this );

playout->addWidget( m_pAxWidget );
playout->setMargin( 0 );

m_pAxWidget->setControl( qsFileName );

QAxObject *pStandard = m_pAxWidget->querySubObject( "CommandBars( const QVariant & )", "Standard" );
pStandard->dynamicCall( "Enabled", true );
pStandard->dynamicCall( "Visible", true );
QAxObject *pFormatting = m_pAxWidget->querySubObject( "CommandBars( const QVariant & )", "Formatting" );
pFormatting->dynamicCall( "Enabled", true );
pFormatting->dynamicCall( "Visible", true );

qDebug() << pStandard->generateDocumentation();
qDebug() << pFormatting->generateDocumentation();

wysota
7th January 2011, 11:56
Ok, also check pStandard->isNull() and pFormatting->isNull(). I have a feeling your sub object calls are invalid. Also try dumping QAxBase::propertyBag() for those subobjects if they are not null. You can dump the properties for your m_pAxWidget object too.

luoyes
8th January 2011, 01:31
Ok, also check pStandard->isNull() and pFormatting->isNull(). I have a feeling your sub object calls are invalid. Also try dumping QAxBase::propertyBag() for those subobjects if they are not null. You can dump the properties for your m_pAxWidget object too.

Thanks for your patience :)

I checked pStandard->isNull() and pFormatting->isNull(). They returned false.

And the properties are right. Both Visible and Enabled are true.

So I think the problem is there is no space to show them. I tried to get CommandBar's parent and make it visible, but that made the word application visible out of my widget.

So maybe it is not very easy to show Word in QWidget with commandBars. It needs much more work to do.

Thanks again.

jiapei100
27th November 2013, 08:43
Did you find the solution already? I'm eagerously looking for the solution all the time these days. Could you please share your solution at your convenience ?


Cheers
Pei

d_stranz
3rd December 2013, 04:22
Did you find the solution already?

I think the original poster's problem is that he was trying to create an embedded MS Word ActiveX object simply by trying to open a Word document. This is completely dependent on the ".doc" extension being assigned to Word documents in MS Windows. On my PC, I use Apache OpenOffice, and when I open a ".doc" file, it opens in OpenOffice, not MS Word.

In order to get this to work correctly, you need to use the GUID for the MS Word COM object in the setControl() call, not the name of the file you want to open. Once you have the MS Word COM object instantiated, you can use it to open the document and display it.

There are plenty of examples on how to do this. I would start with this article (http://qt-project.org/wiki/Using_ActiveX_Object_in_QT) It uses MS Excel, but MS Word is basically the same thing. The COM object model for MS Word can be found here (http://msdn.microsoft.com/en-us/library/bbx26t8w%28v=vs.100%29.aspx).