![]() ![]() Self.underline_()įormat_toolbar.addAction(self.underline_action)įormat_menu.addAction(self.underline_action) Self.underline_tShortcut(QKeySequence.Underline) Self.underline_action = QAction(QIcon(os.path.join('images', 'edit-underline.png')), "Underline", self) alic_()įormat_toolbar.addAction(alic_action)įormat_menu.addAction(alic_action) alic_action = QAction(QIcon(os.path.join('images', 'edit-italic.png')), "Italic", self) Self.bold_(lambda x: (QFont.Bold if x else QFont.Normal))įormat_toolbar.addAction(self.bold_action) Python self.bold_action = QAction(QIcon(os.path.join('images', 'edit-bold.png')), "Bold", self) setFontWeight, setting it to QFont.Bold if enabled, or QFont.Normal if not. Qt provides a set of default weights in the Qt namespace. setFontWeight to set the weight specifically. setFontBold handler, instead we must use. toggled signal is connected to an editor slot to trigger updates. We add a key sequence for each widget to provide standard keyboard shortcuts (e.g. Style handling uses checkable (toggleable) QAction widgets. setFontPointSize using a lambda to wrap the call so we can convert it to a float first. currentIndexChanged signal emits the current value of the combobox when it is updated. setCurrentFont slot on our editor, we can use the dropdown to update the editors' font.įont size is handled with a standard QCombobox which we pre-fill with a default list from the constant FONT_SIZES. ![]() currentFontChanged signal is emitted by the combobox whenever the font is changed, passing the selected font as a parameter. The font dropdown is set up using QFontComboBox a Qt builtin which shows the fonts available on the host system, with each font listed by name with a demo of the font. The editor toolbar is setup using a QToolBar to which we add a number of Receive a signal every time the current selection changes. selectionChanged signal from the editor, we ![]() We need our toolbar to update automatically when clicking/selecting text within the editor. # We need to repeat the size to init the current format. # Setup the QTextEdit editor configuration Super(MainWindow, self)._init_(*args, **kwargs) The default font is set to Times New Roman 12pt. We switch on rich text mode for the editor component and enable auto-formatting (currently only bullet listsįrom *). The QTextEdit component (which we've subclassed as TextEdit) has some additional setup requirements. You need to add the new type to both the `canInsertFromMimeData` and `insertFromMimeData` handlers. You can use these methods to support other types, e.g. Where drop an URL/file (try dragging a file into the window). One where we are adding from an image directly (try dragging an image from a browser window) and one
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |