Fix set/unset of bold text

This commit is contained in:
Miguel Jacq 2025-11-02 10:15:27 +11:00
parent f9d92811dc
commit 39c0cb61da
Signed by: mig5
GPG key ID: 59B3F0C24135C6A9
2 changed files with 6 additions and 4 deletions

View file

@ -28,9 +28,11 @@ class Editor(QTextEdit):
cursor.mergeCharFormat(fmt)
self.mergeCurrentCharFormat(fmt)
@Slot(QFont.Weight)
def apply_weight(self, weight):
@Slot()
def apply_weight(self):
cur = self.currentCharFormat()
fmt = QTextCharFormat()
weight = QFont.Weight.Normal if cur.fontWeight() == QFont.Weight.Bold else QFont.Weight.Bold
fmt.setFontWeight(weight)
self.merge_on_sel(fmt)

View file

@ -6,7 +6,7 @@ from PySide6.QtWidgets import QToolBar
class ToolBar(QToolBar):
boldRequested = Signal(QFont.Weight)
boldRequested = Signal()
italicRequested = Signal()
underlineRequested = Signal()
strikeRequested = Signal()
@ -24,7 +24,7 @@ class ToolBar(QToolBar):
# Bold
bold = QAction("Bold", self)
bold.setShortcut("Ctrl+B")
bold.triggered.connect(lambda: self.boldRequested.emit(QFont.Weight.Bold))
bold.triggered.connect(self.boldRequested)
italic = QAction("Italic", self)
italic.setShortcut("Ctrl+I")