seguso
October 7, 2022, 6:26am
1
In a python plugin, I need a way to simulate a press of “2” (fit to page).
There doesn’t seem to be an action for that, so I’m stuck.
I’m doing an action which: 1) calls show_canvas_only 2) minimizes any windows that are always-on-top 3) calls fit to page (I’m missing this part).
Edit: maybe simulate a keypress with Qt?
Thanks for advice
seguso
October 7, 2022, 7:13am
2
Tried the following but does not work:
wi = app.activeWindow()
ev = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_2, Qt.NoModifier)
QApplication.postEvent(wi.qwindow(), ev)
tom
October 7, 2022, 7:19am
3
At the very least, there’s a ['toggle_zoom_to_fit', 'Toggle Zoom Fit to Page'] action, which works a bit weirdly but might be good enough for your use case.
I’ll see if I can implement Fit to Page as a native action later.
seguso
October 7, 2022, 7:47am
4
It seems to work! Thank you
seguso
October 7, 2022, 8:14am
5
Well, it doesn’t always work, but a workaround is to call zoom_to_100pct and then toggle_zoom_to_fit, in sequence.
tom
October 7, 2022, 11:19pm
6
I’ve submitted a merge request implementing actions for Fit to Page, Fit to Page Width, and Fit to Page Height , so that a workaround shouldn’t be necessary as of 5.2, and so that these actions can be accessed through additional means.
seguso
October 7, 2022, 11:36pm
7
That’s awesome Tom, thank you!