Working text bold shortcut and toolbar

This commit is contained in:
Veronica K. B. Olsen
2019-04-22 21:39:19 +02:00
parent ae19cc7237
commit 6bd2da5e72
2 changed files with 52 additions and 35 deletions
+18 -1
View File
@@ -230,6 +230,22 @@ class GuiDocEditor(QWidget):
return
##
# Key Shortcut Handlers
##
def _doBold(self):
theCursor = self.guiEditor.textCursor()
if theCursor.hasSelection():
selBeg = theCursor.selectionStart()
selEnd = theCursor.selectionEnd()
selText = theCursor.selectedText()
theText = "**%s**" % theCursor.selectedText()
theCursor.removeSelectedText()
theCursor.setPosition(selBeg)
self.guiEditor.textCursor().insertText(theText)
return
##
# GUI Builder
##
@@ -241,8 +257,9 @@ class GuiDocEditor(QWidget):
# Text > Bold
tbTextBold = QAction(QIcon.fromTheme("format-text-bold"), "Bold (Ctrl+B)", toolBar)
tbTextBold.setShortcut("Ctrl+B")
tbTextBold.setStatusTip("Toggle Selected Text Bold")
tbTextBold.setShortcut("Ctrl+B")
tbTextBold.triggered.connect(self._doBold)
toolBar.addAction(tbTextBold)
# Text > Italics