PyQt5 from scratch to make PDF Reader (II)

The previous article, we realized the initial interface PDF reader. This time, the new reading function, can achieve the basic flip and zoom and other operations. However, being only can read a book at the same time.

FIG below shows the effect of:

13406307-8b56a8686effe164.png

Now I come down, during the main new features:

Tab

QTabWidget allow us to display multiple pages in one window. For stacks of this tab, the page is displayed as self.table, that is the initial interface

self.table(QTableWidget) -> self.tabwidget(QTabWidge)。

13406307-9b7d0a67f6bb2cab.png

New tab: Each time you start reading, create a new tab, the name of the file name.

13406307-7ffe88a21a169ca0.png

Among them, we ask the Home tab, that tab stacks is not closed.

13406307-821e96f5ff90c84c.png

Reading interface tab page area corresponding to QScrollArea, QScrollArea support wheel operation. That is, if we scale the PDF page size exceeds QScrollArea size, it will automatically appear rollers, so that we can browse page. Which, MyArea QScrollArea class is overloaded, bind shortcuts to flip and zoom support and other operations.

Pixmap -> label -> area(MyArea) -> vbox(QVBoxLayout) -> tab(QWidget) -> self.tabwidget(QTabWidge)。

13406307-b2370b453a1a19f0.png

Let us look at how the MyArea this class definition:

MyArea(QScrollArea)

Here, we define the init method for receiving the self parameter Reader main class, i.e. the class instance method Reader by self.widget call.

In init_action function, we built four QShortCut example, shortcuts are supported to achieve the reduction, enlargement, the next operation on the previous page.

13406307-ab757e5708ac8798.png

Below, we introduce concrete realization of zoom and flip function:

Zoom function

self.size used to store the page size, self.page it is to achieve the zoom function according to self.size.

13406307-0a041c415629368d.png

Pixmap -> label -> area(MyArea) -> vbox(QVBoxLayout) -> tab(QWidget) -> self.tabwidget(QTabWidge)。

tab tab acquisition target, layout objects get vbox, widget acquisition target area, directly changing the area label control.

13406307-534e77961a6d07bb.png

Then we introduce how to implement flip function

Flip function

This time, we realize the PDF reader can only read one book at the same time, so just flip function controlled by the self.current_page on the line.

self.doc.pageCount the total number of pages, pages of the current can not be negative or greater than the total number of pages. After you've made changes self.current_page, self.set_page operation can be performed directly change the label control on the area.

13406307-18aeca8e790a10dd.png

Guess you like

Origin blog.csdn.net/weixin_34000916/article/details/91010935