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 insertFromMimeData handles the actual adding of the mime content to the document.If you return False a cannot-drop indicator will be shown. Icon with a plus-sign or a drop animation. If this method returns True the window manager will usually show an accept-drop indicator, e.g. This method should return True if you can accept the data being provided. canInsertFromMimeData is a check which confirms whether a particular type can be accepted by.Similar mechanisms are used for other widget types. Parameter source which receives a QMimeData object. ![]() images, or other objects) dropped onto your editor. The two handlers canInsertFromMimeData and insertFromMimeData are Qt's methods for accepting Super(TextEdit, self).insertFromMimeData(source) # If we hit a non-image or non-local URL break the loop and fall outĭocument.addResource(QTextDocument.ImageResource, uuid, image) If u.isLocalFile() and file_ext in IMAGE_EXTENSIONS:ĭocument.addResource(QTextDocument.ImageResource, u, image) Return super(TextEdit, self).canInsertFromMimeData(source)įile_ext = splitext(str(u.toLocalFile()))
0 Comments
Leave a Reply. |