1

I have prepared this example:

import sys
from PyQt5.QtWidgets    import (QApplication, QMainWindow)
from PyQt5              import uic
from PyQt5.QAxContainer import QAxWidget



class MainForm(QMainWindow):
    def __init__(self, parent=None):
        super(MainForm, self).__init__(parent)
    
        uic.loadUi(r"scroll_bar_test.ui", self)

        self.axWidget = QAxWidget('Microsoft Web Browser')

         path = 'C:/Users/Egon/Documents/FotoViewer/scroll_bar_test.docx'
    
         self.axWidget.setControl(path)
         self.setCentralWidget(self.axWidget)
    
def main():
    app = QApplication(sys.argv)
    form = MainForm()
    form.show()
    app.exec_()

if __name__ == '__main__':
    main()

If you start the program it will show a word document but the left side is hidden: enter image description here

if i use the arrow keys to the right i see the whole document: enter image description here

and from there on it is centered fine. My Question is how can the word document can be shown centered right at the start?

enter image description here after using QTimer.singleShot(2000, self.axWidget.updateGeometry)

Meanwhile i found out that these lines center the document:

        self.setCentralWidget(self.axWidget)
        QTimer.singleShot(5, lambda: self.axWidget.setControl(path))
        QTimer.singleShot(5, self.axWidget.updateGeometry)

The time for the Qtimer has to be the same in both shots. Both has to be done with a timer otherwise it doesnt work. Unfurtunately the user sees first a very narrow document like the last foto and then a flash and then the right presented document. Additionaly this doesnt happen on other computer. I have tryed with 3 other people and they didnt have this problmem.

accpert.com
  • 109
  • 11
  • Just to be sure, does the problem still happen even if you remove `loadUi`? – musicamante Jan 20 '22 at 17:59
  • Hi, yes it also happens without loadUi. I have a other example from github, there is no using of loadUi and it is even worse, only a corner of word document is visible. Excel and Powerpoint is shown correct, only word makes this trouble. – accpert.com Jan 21 '22 at 08:40
  • If you resize the window after it's appeared (and before interacting with the ax control), does the problem fix or does it still have the wrong size? – musicamante Jan 21 '22 at 11:59
  • after resizing, for instance maximizing the main window and resize it back, it shows correctly. – accpert.com Jan 21 '22 at 13:28
  • Please be more precise with your testing and their description: does it show correctly only after maximizing ***and*** restoring, or is it correct right after maximizing? And what after basic resizing (through the window borders)? – musicamante Jan 21 '22 at 13:33
  • after maximizing and restoring it shows correct. Precise: run programm it shows wrong, hit maximize it shows correct, restore it shows correct. If i only stretch right or left side it stays wrong although the text is moving. – accpert.com Jan 21 '22 at 13:59
  • Unfortunately I don't have a Windows machine, so I can't test, but I'd suggest trying one of these: 1. use a QWidget container with a basic QVBoxLayout, set that widget as central widget and add the QAxWidget to the layout; 2. delay `setControl()` with a basic `QTimer.singleShot()` (test with different timeouts, including 0); 3. delay a `updateGeometry` with a QTimer: `QTimer.singleShot(100, self.axWidget.updateGeometry)` (again, test with different timeouts); both 2 and 3 could be done in the `resizeEvent()` override with a basic flag (defaults to `False`) to check that it's done just once. – musicamante Jan 21 '22 at 14:48
  • I tryed a lot of combination. Only QTimer.singleShot(2000, self.axWidget.updateGeometry) has an unwanted effect at all. I attached a foto of the result. – accpert.com Jan 22 '22 at 11:41

0 Answers0