|
@ -8,7 +8,7 @@ class PDFLabel(QLabel): |
|
|
def __init__(self, parent): |
|
|
def __init__(self, parent): |
|
|
super().__init__(parent) |
|
|
super().__init__(parent) |
|
|
self.parent = parent |
|
|
self.parent = parent |
|
|
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) |
|
|
|
|
|
|
|
|
self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred) |
|
|
|
|
|
|
|
|
def paintEvent(self, event): |
|
|
def paintEvent(self, event): |
|
|
self.adjustSize() |
|
|
self.adjustSize() |
|
@ -37,7 +37,7 @@ class PDFLabel(QLabel): |
|
|
|
|
|
|
|
|
scaledPix = self.pixmap().scaled(pixSize, Qt.KeepAspectRatio, Qt.SmoothTransformation) |
|
|
scaledPix = self.pixmap().scaled(pixSize, Qt.KeepAspectRatio, Qt.SmoothTransformation) |
|
|
painter.drawPixmap(QPoint(), scaledPix) |
|
|
painter.drawPixmap(QPoint(), scaledPix) |
|
|
# self.setMaximumSize(pixSize) |
|
|
|
|
|
|
|
|
self.setMaximumSize(pixSize) |
|
|
|
|
|
|
|
|
class PDFViewer(QScrollArea): |
|
|
class PDFViewer(QScrollArea): |
|
|
def __init__(self, parent): |
|
|
def __init__(self, parent): |
|
@ -51,6 +51,7 @@ class PDFViewer(QScrollArea): |
|
|
|
|
|
|
|
|
self.scrollAreaContents.setLayout(self.scrollAreaLayout) |
|
|
self.scrollAreaContents.setLayout(self.scrollAreaLayout) |
|
|
self.pixmapList = [] |
|
|
self.pixmapList = [] |
|
|
|
|
|
self.lastVScrollPosition = None |
|
|
|
|
|
|
|
|
def update_pdf(self, pdf): |
|
|
def update_pdf(self, pdf): |
|
|
self.render(pdf) |
|
|
self.render(pdf) |
|
@ -69,6 +70,7 @@ class PDFViewer(QScrollArea): |
|
|
self.pixmapList.append(page.get_pixmap(dpi=300, alpha=False)) |
|
|
self.pixmapList.append(page.get_pixmap(dpi=300, alpha=False)) |
|
|
|
|
|
|
|
|
def clear(self): |
|
|
def clear(self): |
|
|
|
|
|
self.lastVScrollPosition = self.verticalScrollBar().value() |
|
|
while self.scrollAreaLayout.count(): |
|
|
while self.scrollAreaLayout.count(): |
|
|
item = self.scrollAreaLayout.takeAt(0) |
|
|
item = self.scrollAreaLayout.takeAt(0) |
|
|
w = item.widget() |
|
|
w = item.widget() |
|
@ -83,4 +85,9 @@ class PDFViewer(QScrollArea): |
|
|
label.setPixmap(QPixmap.fromImage(qtimg)) |
|
|
label.setPixmap(QPixmap.fromImage(qtimg)) |
|
|
self.scrollAreaLayout.addWidget(label) |
|
|
self.scrollAreaLayout.addWidget(label) |
|
|
|
|
|
|
|
|
# self.scrollAreaLayout.addStretch(1) |
|
|
|
|
|
|
|
|
self.scrollAreaLayout.addStretch(1) |
|
|
|
|
|
|
|
|
|
|
|
# Somewhat of a hack. Should really replace pixmaps in place |
|
|
|
|
|
# rather than removing labels elsewhere in code. |
|
|
|
|
|
if self.lastVScrollPosition: |
|
|
|
|
|
self.verticalScrollBar().setValue(self.lastVScrollPosition) |