Switch app code to PyQt6

This commit is contained in:
Veronica Berglyd Olsen
2025-01-11 20:15:32 +01:00
parent 3ec210df9b
commit 40c4e74d48
64 changed files with 218 additions and 223 deletions
+8 -6
View File
@@ -23,13 +23,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from __future__ import annotations
from PyQt5.QtCore import QEvent, QPropertyAnimation, Qt, pyqtProperty
from PyQt5.QtGui import QMouseEvent, QPainter, QPaintEvent, QResizeEvent
from PyQt5.QtWidgets import QAbstractButton, QWidget
from PyQt6.QtCore import QByteArray, QPropertyAnimation, Qt
from PyQt6.QtGui import QEnterEvent, QMouseEvent, QPainter, QPaintEvent, QResizeEvent
from PyQt6.QtWidgets import QAbstractButton, QWidget
from novelwriter import CONFIG, SHARED
from novelwriter.types import QtMouseLeft, QtNoPen, QtPaintAntiAlias, QtSizeFixed
OFFSET = QByteArray(b"offset") # type: ignore
class NSwitch(QAbstractButton):
@@ -57,7 +59,7 @@ class NSwitch(QAbstractButton):
# Properties
##
@pyqtProperty(int) # type: ignore
@property
def offset(self) -> int: # type: ignore
return self._offset
@@ -121,14 +123,14 @@ class NSwitch(QAbstractButton):
"""Animate the switch on mouse release."""
super().mouseReleaseEvent(event)
if event.button() == QtMouseLeft:
anim = QPropertyAnimation(self, b"offset", self)
anim = QPropertyAnimation(self, OFFSET, self)
anim.setDuration(120)
anim.setStartValue(self._offset)
anim.setEndValue((self._xW - self._xR) if self.isChecked() else self._xR)
anim.start()
return
def enterEvent(self, event: QEvent) -> None:
def enterEvent(self, event: QEnterEvent) -> None:
"""Change the cursor when hovering the button."""
self.setCursor(Qt.CursorShape.PointingHandCursor)
super().enterEvent(event)