Adjust splitter when initially loading PDF Document
Closes: #4 After consideration, we don't want to change the size of the dialog which is the only way to make it fit the PDF. But the geometry is saved, so the user can resize and place it. We did set the splitter to give more space to the PDF.
This commit is contained in:
15
pdfView.py
15
pdfView.py
@@ -1,7 +1,7 @@
|
|||||||
import math
|
import math
|
||||||
|
|
||||||
from PySide6.QtCore import QFile, QModelIndex, QPoint, Signal, Slot
|
from PySide6.QtCore import QFile, QModelIndex, QPoint, QSize, Signal, Slot
|
||||||
from PySide6.QtGui import QCloseEvent
|
from PySide6.QtGui import QCloseEvent, QGuiApplication
|
||||||
from PySide6.QtPdf import QPdfBookmarkModel, QPdfDocument
|
from PySide6.QtPdf import QPdfBookmarkModel, QPdfDocument
|
||||||
from PySide6.QtPdfWidgets import QPdfView
|
from PySide6.QtPdfWidgets import QPdfView
|
||||||
from PySide6.QtWidgets import QComboBox, QDialog, QMenuBar, QSpinBox, QWidget
|
from PySide6.QtWidgets import QComboBox, QDialog, QMenuBar, QSpinBox, QWidget
|
||||||
@@ -118,16 +118,13 @@ class PDFViewer(QDialog, Ui_pdfViewer):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def closeEvent(self, event: QCloseEvent) -> None:
|
def closeEvent(self, event: QCloseEvent) -> None:
|
||||||
|
print("closeEvent")
|
||||||
writeGeometry(self)
|
writeGeometry(self)
|
||||||
super().closeEvent(event)
|
super().closeEvent(event)
|
||||||
return
|
return
|
||||||
|
|
||||||
@Slot(QFile) # type: ignore
|
@Slot(QFile) # type: ignore
|
||||||
def open(self, file: QFile) -> None:
|
def open(self, file: QFile) -> None:
|
||||||
# assert file.exists()
|
|
||||||
# if not file.isOpen():
|
|
||||||
# file.open(QFile.OpenModeFlag.ReadOnly)
|
|
||||||
# self.document.load(file)
|
|
||||||
self.document.load(file.fileName())
|
self.document.load(file.fileName())
|
||||||
document_title = self.document.metaData(
|
document_title = self.document.metaData(
|
||||||
QPdfDocument.MetaDataField.Title
|
QPdfDocument.MetaDataField.Title
|
||||||
@@ -135,6 +132,12 @@ class PDFViewer(QDialog, Ui_pdfViewer):
|
|||||||
self.setWindowTitle(document_title if document_title else "PDF Viewer")
|
self.setWindowTitle(document_title if document_title else "PDF Viewer")
|
||||||
self.page_selected(0)
|
self.page_selected(0)
|
||||||
self.pageSelector.setMaximum(self.document.pageCount() - 1)
|
self.pageSelector.setMaximum(self.document.pageCount() - 1)
|
||||||
|
if self.zoomSelector.currentIndex() == 8:
|
||||||
|
pageSize = self.document.pagePointSize(0)
|
||||||
|
dpi = QGuiApplication.primaryScreen().physicalDotsPerInch()
|
||||||
|
size = QSize(int(pageSize.width()/72*dpi),self.pdfView.height())
|
||||||
|
self.pdfView.resize(size)
|
||||||
|
self.splitter.setSizes([100, size.width()])
|
||||||
return
|
return
|
||||||
|
|
||||||
@Slot(QModelIndex) # type: ignore
|
@Slot(QModelIndex) # type: ignore
|
||||||
|
|||||||
Reference in New Issue
Block a user