本文整理汇总了Python中PySide.QtGui.QTextEdit.setTabStopWidth方法的典型用法代码示例。如果您正苦于以下问题:Python QTextEdit.setTabStopWidth方法的具体用法?Python QTextEdit.setTabStopWidth怎么用?Python QTextEdit.setTabStopWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QTextEdit
的用法示例。
在下文中一共展示了QTextEdit.setTabStopWidth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: App
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import setTabStopWidth [as 别名]
class App(QMainWindow):
def __init__(self, parent=None):
"""Create Qt widgets, connect event handlers."""
super(App, self).__init__(parent)
self.windowTitle = 'DMD | '
self.fileName = ''
self.setWindowTitle(self.windowTitle + 'Unsaved File')
exitAction = QAction('Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(self.close)
openAction = QAction('Open', self)
openAction.setShortcut('Ctrl+O')
openAction.setStatusTip('Open Markdown File')
openAction.triggered.connect(self.openFile)
newAction = QAction('New', self)
newAction.setShortcut('Ctrl+N')
newAction.setStatusTip('New Markdown File')
newAction.triggered.connect(self.newFile)
saveAction = QAction('Save', self)
saveAction.setShortcut('Ctrl+S')
saveAction.setStatusTip('Save File')
saveAction.triggered.connect(self.saveFile)
self.statusBar()
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(newAction)
fileMenu.addAction(openAction)
fileMenu.addAction(saveAction)
fileMenu.addAction(exitAction)
self.setGeometry(300, 300, 1024, 768)
self.show()
self.txtInput = QTextEdit()
self.txtInput.setTabStopWidth(20)
self.webPreview = QWebView()
self.webPreview.setHtml('Start typing...', baseUrl=QUrl('preview'))
self.txtInput.textChanged.connect(self.loadPreview)
splitter = QSplitter()
splitter.addWidget(self.txtInput)
splitter.addWidget(self.webPreview)
self.setCentralWidget(splitter)
def loadPreview(self):
"""Set the QWebView to the value of the parsed document."""
html = markdown2.markdown(self.txtInput.toPlainText())
self.webPreview.setHtml(html, baseUrl=QUrl('preview'))
def openFile(self):
"""Handles opening a file, just like any other text editor."""
self.fileName = QFileDialog.getOpenFileName()[0]
fh = open(self.fileName, 'r')
contents = fh.read()
fh.close()
self.txtInput.setText(contents)
self.setWindowTitle(self.windowTitle + self.fileName)
def newFile(self):
"""Creates a new file, just like any other text editor."""
self.fileName = ''
self.setWindowTitle(self.windowTitle + 'Unsaved File')
self.txtInput.setText('')
def saveFile(self):
"""Saves the file, just like any other text editor."""
if not self.fileName == '':
fh = open(self.fileName, 'w')
fh.write(self.txtInput.toPlainText())
fh.close()
self.setWindowTitle(self.windowTitle + self.fileName)
#.........这里部分代码省略.........