Skip to content

Commit 5df1b7a

Browse files
fix: QPrinter.setPageMargins for Pyside2 (#531)
1 parent 882d53e commit 5df1b7a

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

sportorg/modules/printing/printing.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
import time
44
from multiprocessing import Process, Queue
55

6+
qt_version = 5
67
try:
78
from PySide6.QtCore import QMarginsF, QSizeF
89
from PySide6.QtGui import QPageLayout, QTextDocument
910
from PySide6.QtPrintSupport import QPrinter
1011
from PySide6.QtWidgets import QApplication
12+
13+
qt_version = 6
1114
except ModuleNotFoundError:
1215
from PySide2.QtCore import QMarginsF, QSizeF
1316
from PySide2.QtGui import QPageLayout, QTextDocument
@@ -68,15 +71,24 @@ def run(self):
6871
text_document = QTextDocument()
6972

7073
printer.setFullPage(True)
71-
printer.setPageMargins(
72-
QMarginsF(
74+
if qt_version == 5:
75+
printer.setPageMargins(
7376
self.margin_left,
7477
self.margin_top,
7578
self.margin_right,
7679
self.margin_bottom,
77-
),
78-
QPageLayout.Unit.Millimeter,
79-
)
80+
QPrinter.Unit.Millimeter,
81+
)
82+
else:
83+
printer.setPageMargins(
84+
QMarginsF(
85+
self.margin_left,
86+
self.margin_top,
87+
self.margin_right,
88+
self.margin_bottom,
89+
),
90+
QPageLayout.Unit.Millimeter,
91+
)
8092

8193
page_size = QSizeF()
8294
page_size.setHeight(printer.height())
@@ -119,7 +131,7 @@ def run(self):
119131
)
120132
)
121133
except Exception as e:
122-
logging.error(str(e))
134+
logging.exception(e)
123135

124136

125137
def print_html(

0 commit comments

Comments
 (0)