def createWidget(self, parent): widget = HighlightedTextEdit(parent) # We install an event filter on the text editor to prevent the # contents from being modified outside the custom editor dialog. widget.installEventFilter(self) return widget
def __init__(self, editor, parent=None): super(HighlightedTextEditDialog, self).__init__(parent) self.editor = editor self.textEdit = HighlightedTextEdit() self.textEdit.setCode(editor.getCode()) self.textEdit.installEventFilter(self) okButton = QtGui.QPushButton("&OK") okButton.clicked.connect(self.updateText) cancelButton = QtGui.QPushButton("&Cancel") cancelButton.clicked.connect(self.reject) buttonLayout = QtGui.QHBoxLayout() buttonLayout.addStretch(1) buttonLayout.addWidget(okButton) buttonLayout.addWidget(cancelButton) layout = QtGui.QVBoxLayout() layout.addWidget(self.textEdit) layout.addLayout(buttonLayout) self.setLayout(layout)
def __init__(self, editor, parent=None): QtGui.QDialog.__init__(self, parent) self.editor = editor self.textEdit = HighlightedTextEdit() self.textEdit.setCode(editor.getCode()) self.textEdit.installEventFilter(self) okButton = QtGui.QPushButton("&OK") cancelButton = QtGui.QPushButton("&Cancel") self.connect(okButton, QtCore.SIGNAL("clicked()"), self.updateText) self.connect(cancelButton, QtCore.SIGNAL("clicked()"), self, QtCore.SLOT("reject()")) buttonLayout = QtGui.QHBoxLayout() buttonLayout.addStretch(1) buttonLayout.addWidget(okButton) buttonLayout.addWidget(cancelButton) layout = QtGui.QVBoxLayout() layout.addWidget(self.textEdit) layout.addLayout(buttonLayout) self.setLayout(layout)
def __init__(self, editor, parent = None): QtGui.QDialog.__init__(self, parent) self.editor = editor self.textEdit = HighlightedTextEdit() self.textEdit.setCode(editor.getCode()) self.textEdit.installEventFilter(self) okButton = QtGui.QPushButton("&OK") cancelButton = QtGui.QPushButton("&Cancel") self.connect(okButton, QtCore.SIGNAL("clicked()"), self.updateText) self.connect(cancelButton, QtCore.SIGNAL("clicked()"), self, QtCore.SLOT("reject()")) buttonLayout = QtGui.QHBoxLayout() buttonLayout.addStretch(1) buttonLayout.addWidget(okButton) buttonLayout.addWidget(cancelButton) layout = QtGui.QVBoxLayout() layout.addWidget(self.textEdit) layout.addLayout(buttonLayout) self.setLayout(layout)
class HighlightedTextEditDialog(QtGui.QDialog): """HighlightedTextEditDialog(QtGui.QDialog) Provides a dialog that is used to edit the contents of the custom widget. """ def __init__(self, editor, parent=None): super(HighlightedTextEditDialog, self).__init__(parent) self.editor = editor self.textEdit = HighlightedTextEdit() self.textEdit.setCode(editor.getCode()) self.textEdit.installEventFilter(self) okButton = QtGui.QPushButton("&OK") okButton.clicked.connect(self.updateText) cancelButton = QtGui.QPushButton("&Cancel") cancelButton.clicked.connect(self.reject) buttonLayout = QtGui.QHBoxLayout() buttonLayout.addStretch(1) buttonLayout.addWidget(okButton) buttonLayout.addWidget(cancelButton) layout = QtGui.QVBoxLayout() layout.addWidget(self.textEdit) layout.addLayout(buttonLayout) self.setLayout(layout) def eventFilter(self, obj, event): if obj == self.textEdit: if isinstance(event, QtGui.QKeyEvent): if event.key() == QtCore.Qt.Key_Return and \ int(event.modifiers() & QtCore.Qt.ControlModifier) == QtCore.Qt.ControlModifier: if event.type() == QtGui.QEvent.KeyPress: cursor = self.textEdit.textCursor() char_format = cursor.charFormat() char_format.setFontPointSize(self.textEdit.font.pointSizeF()/2.0) block_format = cursor.blockFormat() cursor.insertBlock(block_format, char_format) self.textEdit.setTextCursor(cursor) return True return False # When we update the contents of the custom widget, we access its # properties via the QDesignerFormWindowInterface API so that Qt Designer # can integrate the changes we make into its undo-redo management. def updateText(self): formWindow = QtDesigner.QDesignerFormWindowInterface.findFormWindow(self.editor) if formWindow: formWindow.cursor().setProperty("code", self.textEdit.getCode()) self.accept()
class HighlightedTextEditDialog(QtGui.QDialog): """HighlightedTextEditDialog(QtGui.QDialog) Provides a dialog that is used to edit the contents of the custom widget. """ def __init__(self, editor, parent=None): super(HighlightedTextEditDialog, self).__init__(parent) self.editor = editor self.textEdit = HighlightedTextEdit() self.textEdit.setCode(editor.getCode()) self.textEdit.installEventFilter(self) okButton = QtGui.QPushButton("&OK") okButton.clicked.connect(self.updateText) cancelButton = QtGui.QPushButton("&Cancel") cancelButton.clicked.connect(self.reject) buttonLayout = QtGui.QHBoxLayout() buttonLayout.addStretch(1) buttonLayout.addWidget(okButton) buttonLayout.addWidget(cancelButton) layout = QtGui.QVBoxLayout() layout.addWidget(self.textEdit) layout.addLayout(buttonLayout) self.setLayout(layout) def eventFilter(self, obj, event): if obj == self.textEdit: if isinstance(event, QtGui.QKeyEvent): if event.key() == QtCore.Qt.Key_Return and \ int(event.modifiers() & QtCore.Qt.ControlModifier) == QtCore.Qt.ControlModifier: if event.type() == QtGui.QEvent.KeyPress: cursor = self.textEdit.textCursor() char_format = cursor.charFormat() char_format.setFontPointSize( self.textEdit.font.pointSizeF() / 2.0) block_format = cursor.blockFormat() cursor.insertBlock(block_format, char_format) self.textEdit.setTextCursor(cursor) return True return False # When we update the contents of the custom widget, we access its # properties via the QDesignerFormWindowInterface API so that Qt Designer # can integrate the changes we make into its undo-redo management. def updateText(self): formWindow = QtDesigner.QDesignerFormWindowInterface.findFormWindow( self.editor) if formWindow: formWindow.cursor().setProperty("code", self.textEdit.getCode()) self.accept()