Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Very Small docx Content View with QAxWidget
QtWS25 Last Chance

Very Small docx Content View with QAxWidget

Scheduled Pinned Locked Moved Solved General and Desktop
qaxcontainerembedded applicworddocx
10 Posts 3 Posters 3.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Manifolds
    wrote on 11 May 2017, 16:26 last edited by
    #1
    #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.

    J 1 Reply Last reply 12 May 2017, 04:45
    0
    • M Manifolds
      11 May 2017, 16:26
      #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.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 12 May 2017, 04:45 last edited by
      #2

      @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?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply 12 May 2017, 15:27
      0
      • J jsulm
        12 May 2017, 04:45

        @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?

        M Offline
        M Offline
        Manifolds
        wrote on 12 May 2017, 15:27 last edited by Manifolds 5 Dec 2017, 15:39
        #3

        @jsulm

        Just one sentence.

        My Qt Version is 5.8 win32 msvc visual studio 2015.
        My OS is Win10 64bit.
        My Office version is 2016 64bit

        1 Reply Last reply
        0
        • E Offline
          E Offline
          Eddy
          wrote on 12 May 2017, 16:57 last edited by
          #4

          Hi,

          If you know the size you would prefer you could use :
          axw->setMinimumSize(1024,700);

          Eddy

          Qt Certified Specialist
          www.edalsolutions.be

          M 1 Reply Last reply 13 May 2017, 01:20
          0
          • E Eddy
            12 May 2017, 16:57

            Hi,

            If you know the size you would prefer you could use :
            axw->setMinimumSize(1024,700);

            Eddy

            M Offline
            M Offline
            Manifolds
            wrote on 13 May 2017, 01:20 last edited by
            #5

            @Eddy

            No , this can't change anything.

            http://pan.baidu.com/s/1o83AO7g

            1 Reply Last reply
            0
            • E Offline
              E Offline
              Eddy
              wrote on 13 May 2017, 06:09 last edited by
              #6

              Hi Manifolds,

              The link you posted is dead, can you give us the correct link please?

              Eddy

              Qt Certified Specialist
              www.edalsolutions.be

              M 1 Reply Last reply 13 May 2017, 13:17
              0
              • E Eddy
                13 May 2017, 06:09

                Hi Manifolds,

                The link you posted is dead, can you give us the correct link please?

                Eddy

                M Offline
                M Offline
                Manifolds
                wrote on 13 May 2017, 13:17 last edited by
                #7

                @Eddy

                you can't view this file outside China.

                new link on OnDrive:

                https://1drv.ms/i/s!AukiP6uHSpGK1DlJ7uJYURjuqMmR

                1 Reply Last reply
                0
                • E Offline
                  E Offline
                  Eddy
                  wrote on 13 May 2017, 19:08 last edited by
                  #8

                  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

                  Qt Certified Specialist
                  www.edalsolutions.be

                  M 1 Reply Last reply 14 May 2017, 01:03
                  2
                  • E Eddy
                    13 May 2017, 19:08

                    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

                    M Offline
                    M Offline
                    Manifolds
                    wrote on 14 May 2017, 01:03 last edited by Manifolds
                    #9

                    @Eddy

                    Solved, Thank you very much.

                    I just want to view the word file, a simple job.

                    1 Reply Last reply
                    0
                    • E Offline
                      E Offline
                      Eddy
                      wrote on 14 May 2017, 11:57 last edited by
                      #10

                      You're welcome

                      Eddy

                      Qt Certified Specialist
                      www.edalsolutions.be

                      1 Reply Last reply
                      1

                      10/10

                      14 May 2017, 11:57

                      • Login

                      • Login or register to search.
                      10 out of 10
                      • First post
                        10/10
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved