Very Small docx Content View with QAxWidget
-
#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? -
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