当前位置: 首页>>代码示例>>Python>>正文


Python QCompleter.setModelSorting方法代码示例

本文整理汇总了Python中PyQt5.QtWidgets.QCompleter.setModelSorting方法的典型用法代码示例。如果您正苦于以下问题:Python QCompleter.setModelSorting方法的具体用法?Python QCompleter.setModelSorting怎么用?Python QCompleter.setModelSorting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtWidgets.QCompleter的用法示例。


在下文中一共展示了QCompleter.setModelSorting方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MainWindow

# 需要导入模块: from PyQt5.QtWidgets import QCompleter [as 别名]
# 或者: from PyQt5.QtWidgets.QCompleter import setModelSorting [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.")
开发者ID:death-finger,项目名称:Scripts,代码行数:62,代码来源:customcompleter.py

示例2: __init__

# 需要导入模块: from PyQt5.QtWidgets import QCompleter [as 别名]
# 或者: from PyQt5.QtWidgets.QCompleter import setModelSorting [as 别名]
    def __init__(self, namespace, parent):
        """Constructor.

        Args:
            namespace: The local namespace of the interpreter.
        """
        super().__init__(parent)
        self.update_font()
        objreg.get('config').changed.connect(self.update_font)
        self.textChanged.connect(self.on_text_changed)

        self._rlcompleter = rlcompleter.Completer(namespace)
        qcompleter = QCompleter(self)
        self._model = QStringListModel(qcompleter)
        qcompleter.setModel(self._model)
        qcompleter.setCompletionMode(
            QCompleter.UnfilteredPopupCompletion)
        qcompleter.setModelSorting(
            QCompleter.CaseSensitivelySortedModel)
        self.setCompleter(qcompleter)

        self._history = cmdhistory.History()
        self.returnPressed.connect(self.on_return_pressed)
开发者ID:anweshknayak,项目名称:qutebrowser,代码行数:25,代码来源:console.py


注:本文中的PyQt5.QtWidgets.QCompleter.setModelSorting方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。