Creating the View widget¶
from PyQt5.QtWidgets import QApplication import qpageview app = QApplication() v = qpageview.View() v.resize(900, 500) v.show()
Load a PDF file with:
or images, or SVG files:
import glob v.loadImages(glob.glob("*.jpg")) v.loadSvgs(glob.glob("*.svg"))
It is also possible to display pages originating from different sources at the same time in a View, see Advanced usage.
To clear the View again:
Controlling the display¶
You can interact in the normal way with the widget, scrolling and zooming. Note the almost infinite zoom, thanks to the tile-based rendering engine.
There are various methods to change things, like rotation:
v.rotateRight() v.rotateLeft() v.setRotation(2) # or v.setRotation(qpageview.Rotate_180)
v.zoomIn() v.zoomOut() v.setZoomFactor(2.0)
or how to fit the document while resizing the View widget:
v.setViewMode(qpageview.FitWidth) # fits the page(s) in the width v.setViewMode(qpageview.FitHeight) # fits the page's height v.setViewMode(qpageview.FitBoth) # shows the full page v.setViewMode(qpageview.FixedScale) # don't adjust zoom to the widget
Setting the zoomFactor automatically switches to the FixedScale mode.
Change the orientation:
Change the continuous mode:
v.setContinuousMode(False) # only display the current page(s) v.setContinuousMode(True) # display all pages
Change the layout mode:
v.setPageLayoutMode("double_right") # Two pages, first page right v.setPageLayoutMode("double_left") # Two pages, first page left v.setPageLayoutMode("single") # Single pages v.setPageLayoutMode("raster") # Shows pages in a grid
pageLayoutModes() returns a dictionary mapping the
available layout mode names to the constructors of their corresponding layout
engines. By making new
LayoutEngine subclasses, you can
implement more layout modes, and you can reimplement
All these properties have “getter” couterparts, like
You can add a
from qpageview.magnifier import Magnifier m = Magnifier() v.setMagnifier(m)
Now, Ctrl+click in the View, and the Magnifier appears. You can also show the Magnifier programmatically with:
m.show() # or v.magnifier().show()
Now you can only get it away with:
Ctrl+Wheel in the magnifier zooms the magnifier instead of the whole View. Shift+Ctrl+Wheel resizes the magnifier.
You can add a
Rubberband, to select a square
from qpageview.rubberband import Rubberband r = Rubberband() v.setRubberband(r)
By default with the right mousebutton you can select a region. The rubberband has various methods to access the selected area, just the rectangle, or the rectangle of every page the selection touches, or the selected square as an image or, depending on the underlying page type, the text or clickable links that fall in the selected region.
Controlling the behaviour¶
By default, the View has smooth and kinetic scrolling. Kinetic scrolling means that the View does not move the pages at once, but always scrolls with a decreasing speed to the desired location, which is easier on the eyes.
If you want to disable kinetic scrolling altogether, set the
kineticScrollingEnabled attribute of the View to
If you only want to disable kinetic scrolling when paging through the document
using the methods mentioned under Navigating in the View, you can leave
kineticScrollingEnabled to True, but set
kineticPagingEnabled to False.
The user can zoom in and out with Ctrl+Mousewheel, which is expected behaviour.
You can disable wheel zooming by setting the
attribute of View to False.