Very Small docx Content View with QAxWidget
-
wrote on 11 May 2017, 16:26 last edited by
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QAxObject> #include <QAxWidget> #include <QString> #include <QTextEdit> class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); ~MainWindow(); void open(const QString&); private: QAxWidget* axw; }; #endif // MAINWINDOW_H
#include "mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { } MainWindow::~MainWindow() { } void MainWindow::open(const QString &fnm) { if(fnm.isEmpty()) return; if(fnm.endsWith("doc") || fnm.endsWith("docx")){ axw = new QAxWidget("Word.Application", nullptr); setCentralWidget(axw); axw->setGeometry(0,0,1024,700); axw->setControl(fnm); axw->show(); } }
#include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.setGeometry(20,20,1366,768); w.show(); w.open("C:/Users/xxx/Desktop/test.docx"); return a.exec(); }
/////////
When I test with doc file, every thing is OK. -
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QAxObject> #include <QAxWidget> #include <QString> #include <QTextEdit> class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); ~MainWindow(); void open(const QString&); private: QAxWidget* axw; }; #endif // MAINWINDOW_H
#include "mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { } MainWindow::~MainWindow() { } void MainWindow::open(const QString &fnm) { if(fnm.isEmpty()) return; if(fnm.endsWith("doc") || fnm.endsWith("docx")){ axw = new QAxWidget("Word.Application", nullptr); setCentralWidget(axw); axw->setGeometry(0,0,1024,700); axw->setControl(fnm); axw->show(); } }
#include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.setGeometry(20,20,1366,768); w.show(); w.open("C:/Users/xxx/Desktop/test.docx"); return a.exec(); }
/////////
When I test with doc file, every thing is OK.@Manifolds Did you try to call axw->setGeometry(0,0,1024,700); after axw->setControl(fnm); ?
Does the docx contain anything? What is the page format in that docx? -
@Manifolds Did you try to call axw->setGeometry(0,0,1024,700); after axw->setControl(fnm); ?
Does the docx contain anything? What is the page format in that docx? -
wrote on 12 May 2017, 16:57 last edited by
Hi,
If you know the size you would prefer you could use :
axw->setMinimumSize(1024,700);Eddy
-
Hi,
If you know the size you would prefer you could use :
axw->setMinimumSize(1024,700);Eddy
wrote on 13 May 2017, 01:20 last edited by -
wrote on 13 May 2017, 06:09 last edited by
Hi Manifolds,
The link you posted is dead, can you give us the correct link please?
Eddy
-
wrote on 13 May 2017, 13:17 last edited by
you can't view this file outside China.
new link on OnDrive:
-
wrote on 13 May 2017, 19:08 last edited by
Hi Manifolds,
instead of
axw = new QAxWidget("Word.Application", nullptr); setCentralWidget(axw); axw->setGeometry(0,0,1024,700); axw->setControl(fnm); axw->show();
Try this
QAxWidget* axw=new QAxWidget (); axw->setControl(fnm); axw-> show (); setCentralWidget(axw);
And the word document is filling up all available space of the QMainWindow as you wish. At least that is what I get.
You are using "Word.application" instead of a "Word.Document". Those are different COM objects with different CLSID's. Using getDocumentation, you can check this out.
I think the sizehints were messed up because of the order you call the functions.(you can check that with sizeHint())Normally I use a Word.application to start with, then one can get "Documents" from it using QuerySubObject and from Documents you get at Document, where you wanted to land directly.
Out of curiosity, what is it you want to achieve exactly? Just opening one file or do you want to make an application that can open different documents?
Cheers,
Eddy
-
Hi Manifolds,
instead of
axw = new QAxWidget("Word.Application", nullptr); setCentralWidget(axw); axw->setGeometry(0,0,1024,700); axw->setControl(fnm); axw->show();
Try this
QAxWidget* axw=new QAxWidget (); axw->setControl(fnm); axw-> show (); setCentralWidget(axw);
And the word document is filling up all available space of the QMainWindow as you wish. At least that is what I get.
You are using "Word.application" instead of a "Word.Document". Those are different COM objects with different CLSID's. Using getDocumentation, you can check this out.
I think the sizehints were messed up because of the order you call the functions.(you can check that with sizeHint())Normally I use a Word.application to start with, then one can get "Documents" from it using QuerySubObject and from Documents you get at Document, where you wanted to land directly.
Out of curiosity, what is it you want to achieve exactly? Just opening one file or do you want to make an application that can open different documents?
Cheers,
Eddy
-
wrote on 14 May 2017, 11:57 last edited by
You're welcome
Eddy
8/10