本文整理汇总了Python中PyQt5.QtWidgets.QPlainTextEdit.setModel方法的典型用法代码示例。如果您正苦于以下问题:Python QPlainTextEdit.setModel方法的具体用法?Python QPlainTextEdit.setModel怎么用?Python QPlainTextEdit.setModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QPlainTextEdit
的用法示例。
在下文中一共展示了QPlainTextEdit.setModel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DialogSqlQuery
# 需要导入模块: from PyQt5.QtWidgets import QPlainTextEdit [as 别名]
# 或者: from PyQt5.QtWidgets.QPlainTextEdit import setModel [as 别名]
class DialogSqlQuery(QDialog):
"""
Dialog for Sql query
"""
# Slots
@pyqtSlot()
def __populate_select_template(self):
self.__sql_input.setPlainText(self.__db_access.compose_select(self.__db_name,
self.__table_name,
self.__columns,
self.__columns[0]))
@pyqtSlot()
def __populate_update_template(self):
self.__sql_input.setPlainText(self.__db_access.compose_update(self.__db_name,
self.__table_name,
self.__columns))
@pyqtSlot()
def __execute_query(self):
sql = self.__sql_input.toPlainText()
if sql == '':
return
#self.__action_dict[[p for p in sql.split(' ') if p != ''][0]]()
#self.__output.model().setColumnCount(len(self.__columns))
#for (i, v) in zip(range(len(self.__columns)), self.__columns):
# self.__output.model().setHeaderData(i, Qt.Horizontal, v)
lst = self.__db_access.query(sql)
#for values in lst:
# items = []
# for v in values:
# items.append(QStandardItem(str(v)))
# self.__output.model().appendRow(items)
@pyqtSlot()
def __clear_query_input(self):
self.__sql_input.clear()
@pyqtSlot()
def __populate_delete_template(self):
self.__sql_input.setPlainText(self.__db_access.compose_delete(self.__db_name, self.__table_name))
@pyqtSlot()
def __populate_insert_template(self):
self.__sql_input.setPlainText(self.__db_access.compose_insert(self.__db_name, self.__table_name, self.__columns))
@staticmethod
def none_to_space(s=None) -> str:
if s is None:
return ' '
return s
def __init__(self, db_access, table_name, db_name, columns):
super().__init__()
self.__init_consts()
self.__init_ui()
self.__db_access = db_access
self.__table_name = self.none_to_space(table_name)
self.__db_name = self.none_to_space(db_name)
self.__columns = self.none_to_space(columns)
self.__setup_output_creation()
def __setup_output_creation(self) -> {dict}:
return {
self.__SELECT: self.__create_treeview_output,
self.__UPDATE: self.__create_plaintext_output,
self.__DELETE: self.__create_plaintext_output,
self.__INSERT: self.__create_plaintext_output
}
def __create_treeview_output(self):
self.__output = QTableView()
self.__output.setModel(QStandardItemModel())
def __create_plaintext_output(self):
self.__output = QPlainTextEdit()
def __init_consts(self):
self.__LBL_SQL_QUERY= QLabel('SQL: ')
self.__LBL_SQL_TEMPLATES = QLabel('Templates: ')
self.__TITLE = 'SQL Query'
self.__GO = 'Go'
self.__CLEAR = 'Clear'
self.__CANCEL = 'Cancel'
self.__SELECT = 'SELECT'
self.__UPDATE = 'UPDATE'
self.__DELETE = 'DELETE'
self.__INSERT = 'INSERT'
self.__WIDTH = 800
self.__HEIGHT = 600
self.__SQL_INPUT_HEIGHT = 100
def __init_ui(self):
self.setLayout(self.__init_layout())
self.__setup_event_handlers()
self.setWindowTitle(self.__TITLE)
self.setFixedWidth(self.__WIDTH)
self.setFixedHeight(self.__HEIGHT)
self.setModal(True)
self.__action_dict = self.__setup_output_creation()
#.........这里部分代码省略.........