本文整理汇总了Python中PyQt5.QtWidgets.QCompleter.setWrapAround方法的典型用法代码示例。如果您正苦于以下问题:Python QCompleter.setWrapAround方法的具体用法?Python QCompleter.setWrapAround怎么用?Python QCompleter.setWrapAround使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QCompleter
的用法示例。
在下文中一共展示了QCompleter.setWrapAround方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QCompleter [as 别名]
# 或者: from PyQt5.QtWidgets.QCompleter import setWrapAround [as 别名]
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.createMenu()
self.completingTextEdit = TextEdit()
self.completer = QCompleter(self)
self.completer.setModel(self.modelFromFile(':/resources/wordlist.txt'))
self.completer.setModelSorting(QCompleter.CaseInsensitivelySortedModel)
self.completer.setCaseSensitivity(Qt.CaseInsensitive)
self.completer.setWrapAround(False)
self.completingTextEdit.setCompleter(self.completer)
self.setCentralWidget(self.completingTextEdit)
self.resize(500, 300)
self.setWindowTitle("Completer")
def createMenu(self):
exitAction = QAction("Exit", self)
aboutAct = QAction("About", self)
aboutQtAct = QAction("About Qt", self)
exitAction.triggered.connect(QApplication.instance().quit)
aboutAct.triggered.connect(self.about)
aboutQtAct.triggered.connect(QApplication.instance().aboutQt)
fileMenu = self.menuBar().addMenu("File")
fileMenu.addAction(exitAction)
helpMenu = self.menuBar().addMenu("About")
helpMenu.addAction(aboutAct)
helpMenu.addAction(aboutQtAct)
def modelFromFile(self, fileName):
f = QFile(fileName)
if not f.open(QFile.ReadOnly):
return QStringListModel(self.completer)
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
words = []
while not f.atEnd():
line = f.readLine().trimmed()
if line.length() != 0:
try:
line = str(line, encoding='ascii')
except TypeError:
line = str(line)
words.append(line)
QApplication.restoreOverrideCursor()
return QStringListModel(words, self.completer)
def about(self):
QMessageBox.about(self, "About",
"This example demonstrates the different features of the "
"QCompleter class.")