diff --git a/csgui/pdfViewer.py b/csgui/pdfViewer.py index f988e9c..7a29928 100644 --- a/csgui/pdfViewer.py +++ b/csgui/pdfViewer.py @@ -8,7 +8,7 @@ class PDFLabel(QLabel): def __init__(self, parent): super().__init__(parent) self.parent = parent - self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) + self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred) def paintEvent(self, event): self.adjustSize() @@ -37,7 +37,7 @@ class PDFLabel(QLabel): scaledPix = self.pixmap().scaled(pixSize, Qt.KeepAspectRatio, Qt.SmoothTransformation) painter.drawPixmap(QPoint(), scaledPix) - # self.setMaximumSize(pixSize) + self.setMaximumSize(pixSize) class PDFViewer(QScrollArea): def __init__(self, parent): @@ -51,6 +51,7 @@ class PDFViewer(QScrollArea): self.scrollAreaContents.setLayout(self.scrollAreaLayout) self.pixmapList = [] + self.lastVScrollPosition = None def update_pdf(self, pdf): self.render(pdf) @@ -69,6 +70,7 @@ class PDFViewer(QScrollArea): self.pixmapList.append(page.get_pixmap(dpi=300, alpha=False)) def clear(self): + self.lastVScrollPosition = self.verticalScrollBar().value() while self.scrollAreaLayout.count(): item = self.scrollAreaLayout.takeAt(0) w = item.widget() @@ -83,4 +85,9 @@ class PDFViewer(QScrollArea): label.setPixmap(QPixmap.fromImage(qtimg)) 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)