def create_textbox_dialog(content: str, title: str, parent) -> QDialog:
d = QDialog(parent)
d.resize(800, 600)
d.setWindowTitle(title)
layout = QVBoxLayout(d)
text_edit = QPlainTextEdit(content)
text_edit.setReadOnly(True)
layout.addWidget(text_edit)
d.setLayout(layout)
return d
python类QPlainTextEdit()的实例源码
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(911, 688)
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(Form)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.splitter = QtWidgets.QSplitter(Form)
self.splitter.setOrientation(QtCore.Qt.Horizontal)
self.splitter.setObjectName("splitter")
self.editorBox = QtWidgets.QGroupBox(self.splitter)
self.editorBox.setObjectName("editorBox")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.editorBox)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.plainTextEdit = QtWidgets.QPlainTextEdit(self.editorBox)
self.plainTextEdit.setObjectName("plainTextEdit")
self.verticalLayout_2.addWidget(self.plainTextEdit)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.clearButton = QtWidgets.QPushButton(self.editorBox)
self.clearButton.setObjectName("clearButton")
self.horizontalLayout.addWidget(self.clearButton)
self.previewButton = QtWidgets.QPushButton(self.editorBox)
self.previewButton.setObjectName("previewButton")
self.horizontalLayout.addWidget(self.previewButton)
self.verticalLayout_2.addLayout(self.horizontalLayout)
self.horizontalLayout_2.addLayout(self.verticalLayout_2)
self.previewerBox = QtWidgets.QGroupBox(self.splitter)
self.previewerBox.setObjectName("previewerBox")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.previewerBox)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.webView = QtWebKitWidgets.QWebView(self.previewerBox)
self.webView.setUrl(QtCore.QUrl("about:blank"))
self.webView.setObjectName("webView")
self.horizontalLayout_3.addWidget(self.webView)
self.horizontalLayout_4.addWidget(self.splitter)
self.retranslateUi(Form)
self.clearButton.clicked.connect(self.plainTextEdit.clear)
QtCore.QMetaObject.connectSlotsByName(Form)
def __init__(self, parent=None):
super(LogDialog, self).__init__()
self.parent = parent
self.logwindow = QPlainTextEdit(parent=self.parent)
self.logwindow.setReadOnly(True)
self.logwindow.setStyleSheet("QPlainTextEdit {background-color:gray}")
layout = QVBoxLayout(self)
layout.addWidget(self.logwindow)
self.setWindowIcon(get_icon("log_file.png"))
self.setWindowTitle("Log record")
def __init__(self, window_width=1000, window_height=950):
super().__init__()
# Initialize Plain Text Widget
self.text_widget = QtWidgets.QPlainTextEdit()
# Default Mode to Insertion
self.insert = True
# EventFilter FocusOut
self._filter = Filter()
# Setup Shortcuts
self.shift_tab = QtWidgets.QShortcut(QtGui.QKeySequence('Shift+Tab'), self)
#self.shift_tab.activated.setFocus()
# Default start up File
self.file_name = 'Untitled.txt'
self.file_path = ['/', '']
self.file_type = self.file_name.split('.')[-1]
self.syntax = highlighter.PythonHighlighter(self.text_widget.document())
self.assign_syntax_def()
# Initialize Menus
self.menu_bar = self.menuBar()
self.file_menu()
self.edit_menu()
self.format_menu()
self.preferences_menu()
self.finder_toolbar()
# Set Default Pallete
self.default_visual()
# Initialize UI Related Properties
self.notepad_ui()
self.setCentralWidget(self.text_widget)
self.setWindowIcon(QtGui.QIcon('assets/icons/notepad.png'))
self.resize(window_width, window_height)
# Center the main window to the screen
self.center()
self.show()
def keyPressEvent(self, iQKeyEvent):
if QtWidgets.QApplication.keyboardModifiers() == QtCore.Qt.ControlModifier:
if iQKeyEvent.key() == QtCore.Qt.Key_Enter or iQKeyEvent.key() == QtCore.Qt.Key_Return:
logging.debug("CtrlModifier + Enter/Return")
self.ref_central.add_text_to_diary()
self.key_press_down_for_question_list_signal.emit()
# -TODO: Change name of signals to focus on goal rather than origin
return
elif QtWidgets.QApplication.keyboardModifiers() == QtCore.Qt.AltModifier:
if iQKeyEvent.key() == QtCore.Qt.Key_Down:
logging.debug("AltModifier + Key_Down")
self.key_press_down_for_question_list_signal.emit()
return
elif iQKeyEvent.key() == QtCore.Qt.Key_Up:
logging.debug("AltModifier + Key_Up")
self.key_press_up_for_question_list_signal.emit()
return
elif iQKeyEvent.key() >= QtCore.Qt.Key_1 or iQKeyEvent.key() >= QtCore.Qt.Key_9:
logging.debug("AltModifier + Key_0-9")
new_row_int = 0
if iQKeyEvent.key() == QtCore.Qt.Key_1:
new_row_int = 0
elif iQKeyEvent.key() == QtCore.Qt.Key_2:
new_row_int = 1
elif iQKeyEvent.key() == QtCore.Qt.Key_3:
new_row_int = 2
elif iQKeyEvent.key() == QtCore.Qt.Key_4:
new_row_int = 3
elif iQKeyEvent.key() == QtCore.Qt.Key_5:
new_row_int = 4
elif iQKeyEvent.key() == QtCore.Qt.Key_6:
new_row_int = 5
elif iQKeyEvent.key() == QtCore.Qt.Key_7:
new_row_int = 6
elif iQKeyEvent.key() == QtCore.Qt.Key_8:
new_row_int = 7
elif iQKeyEvent.key() == QtCore.Qt.Key_9:
new_row_int = 8
### self.questions_composite_w3.list_widget.setCurrentRow(new_row_int)
self.key_press_0_9_for_question_list_signal.emit(new_row_int)
return
elif QtWidgets.QApplication.keyboardModifiers() == QtCore.Qt.ShiftModifier:
pass
else: # -no keyboard modifier
if iQKeyEvent.key() == QtCore.Qt.Key_Enter or iQKeyEvent.key() == QtCore.Qt.Key_Return:
# -http://doc.qt.io/qt-5/qguiapplication.html#keyboardModifiers
# -Please note that the modifiers are placed directly in the QtCore.Qt namespace
# Alternatively:
# if QtWidgets.QApplication.keyboardModifiers() == QtCore.Qt.ShiftModifier:
# -using bitwise and to find out if the shift key is pressed
logging.debug("enter or return key pressed in textedit area")
self.ref_central.add_text_to_diary()
return
QtWidgets.QPlainTextEdit.keyPressEvent(self, iQKeyEvent)
# -if we get here it means that the key has not been captured elsewhere (or possibly
# (that the key has been captured but that we want "double handling" of the key event)