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


Python QtGui.QTextCursor方法代码示例

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


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

示例1: generate_page_positions

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCursor [as 别名]
def generate_page_positions(self):
        self.verticalScrollBar().setValue(0)

        cursorEnd = QtGui.QTextCursor(self.document())
        cursorEnd.movePosition(QtGui.QTextCursor.End)

        self.page_cursors = []

        while True:
            cursorTopLeft = self.cursorForPosition(
                self.viewport().rect().topLeft())
            cursorBottomLeft = self.cursorForPosition(
                self.viewport().rect().bottomLeft())
            cursorBottomRight = self.cursorForPosition(
                self.viewport().rect().bottomRight())

            self.page_cursors.append(
                (cursorTopLeft.position(), cursorBottomRight.position()))

            self.move_to_cursor(cursorBottomRight)

            # TODO
            # See if this requires a failsafe per number of iterations
            if cursorEnd.position() == cursorBottomRight.position():
                break 
开发者ID:BasioMeusPuga,项目名称:Lector,代码行数:27,代码来源:contentwidgets.py

示例2: set_page

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCursor [as 别名]
def set_page(self, originalCursor):
        required_position = originalCursor.position()

        if self.text_mode == 'flow':
            page_start = required_position

        if self.text_mode == 'singlePage':
            for count, i in enumerate(self.page_cursors):
                if i[0] <= required_position < i[1]:
                    page_start = i[0]
                    self.page_number = count
                    break

        cursorGoTo = QtGui.QTextCursor(self.document())
        cursorGoTo.setPosition(page_start)
        self.move_to_cursor(cursorGoTo) 
开发者ID:BasioMeusPuga,项目名称:Lector,代码行数:18,代码来源:contentwidgets.py

示例3: turn_page

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCursor [as 别名]
def turn_page(self, direction):
        self.page_number += direction

        if self.page_number in (-1, self.document().pageCount()):
            self.page_number = 0
            self.common_functions.change_chapter(direction)
            self.create_pages()
        else:
            try:
                page_start = self.page_cursors[self.page_number][0]
                cursorGoTo = QtGui.QTextCursor(self.document())
                cursorGoTo.setPosition(page_start)
                self.move_to_cursor(cursorGoTo)
                self.set_top_line_cleanly()
            except IndexError:
                pass 
开发者ID:BasioMeusPuga,项目名称:Lector,代码行数:18,代码来源:contentwidgets.py

示例4: __init__

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCursor [as 别名]
def __init__(self, parent=None, lines=[]):
        super(SourceDocument, self).__init__(parent)
        self.parent = parent

        self.setDefaultFont(QtGui.QFont('Monaco', 9, QtGui.QFont.Light))

        cursor = QtGui.QTextCursor(self)  # position=0x0
        self.binding = {}

        # save the cursor position before each interesting element
        for section, L in lines:
            for t in L:
                if t[0] in BINDINGS_NAMES:
                    self.binding[cursor.position()] = t
                cursor.insertText(t[1]) 
开发者ID:amimo,项目名称:dcc,代码行数:17,代码来源:sourcewindow.py

示例5: cursor_position_changed

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCursor [as 别名]
def cursor_position_changed(self):
        """Used to detect when cursor change position and to auto select word
           underneath it"""
        log.debug("cursor_position_changed")

        cur = self.textCursor()
        log.debug(cur.position())
        log.debug(cur.selectedText())
        if len(cur.selectedText()) == 0:
            cur.select(QtGui.QTextCursor.WordUnderCursor)
            self.setTextCursor(cur)
            # log.debug("cursor: %s" % cur.selectedText()) 
开发者ID:amimo,项目名称:dcc,代码行数:14,代码来源:sourcewindow.py

示例6: format_preview

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCursor [as 别名]
def format_preview(self):
        # Needed to clear the preview of annotation ickiness
        cursor = QtGui.QTextCursor()
        self.previewView.setTextCursor(cursor)

        self.previewView.setText('Vidistine nuper imagines moventes bonas?')
        profile_index = self.main_window.bookToolBar.profileBox.currentIndex()
        current_profile = self.main_window.bookToolBar.profileBox.itemData(
            profile_index, QtCore.Qt.UserRole)

        if not current_profile:
            return

        font = current_profile['font']
        self.foreground = current_profile['foreground']
        background = current_profile['background']
        font_size = current_profile['font_size']

        self.previewView.setStyleSheet(
            "QTextEdit {{font-family: {0}; font-size: {1}px; color: {2}; background-color: {3}}}".format(
                font, font_size, self.foreground.name(), background.name()))

        block_format = QtGui.QTextBlockFormat()
        block_format.setAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignHCenter)

        cursor = self.previewView.textCursor()
        while True:
            old_position = cursor.position()
            cursor.mergeBlockFormat(block_format)
            cursor.movePosition(QtGui.QTextCursor.NextBlock, 0, 1)
            new_position = cursor.position()
            if old_position == new_position:
                break 
开发者ID:BasioMeusPuga,项目名称:Lector,代码行数:35,代码来源:settingsdialog.py

示例7: clear_annotations

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCursor [as 别名]
def clear_annotations(self):
        if not self.are_we_doing_images_only:
            cursor = self.pw.textCursor()
            cursor.setPosition(0)
            cursor.movePosition(
                QtGui.QTextCursor.End, QtGui.QTextCursor.KeepAnchor)

            previewCharFormat = QtGui.QTextCharFormat()
            previewCharFormat.setFontStyleStrategy(
                QtGui.QFont.PreferAntialias)
            cursor.setCharFormat(previewCharFormat)
            cursor.clearSelection()
            self.pw.setTextCursor(cursor) 
开发者ID:BasioMeusPuga,项目名称:Lector,代码行数:15,代码来源:contentwidgets.py

示例8: cursor_position_changed

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCursor [as 别名]
def cursor_position_changed(self):
        '''Used to detect when cursor change position and to auto select word
           underneath it'''
        androconf.debug("cursor_position_changed")

        cur = self.textCursor()
        androconf.debug(cur.position())
        androconf.debug(cur.selectedText())
        if len(cur.selectedText()) == 0:
            cur.select(QtGui.QTextCursor.WordUnderCursor)
            self.setTextCursor(cur)
            #androconf.debug("cursor: %s" % cur.selectedText()) 
开发者ID:xtiankisutsa,项目名称:MARA_Framework,代码行数:14,代码来源:sourcewindow.py

示例9: textCursor

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCursor [as 别名]
def textCursor(self) -> QTextCursor:
        return super().textCursor() 
开发者ID:jopohl,项目名称:urh,代码行数:4,代码来源:TextEditProtocolView.py

示例10: move_to_next_search_text

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCursor [as 别名]
def move_to_next_search_text(self):
        """ Push button pressed to move to next search text position. """

        self.search_index += 1
        if self.search_index == len(self.search_indices):
            self.search_index = 0
        cur = self.ui.textEdit.textCursor()
        next_result = self.search_indices[self.search_index]
        # next_result is a tuple containing a dictonary of {name, id, fullltext, memo, owner, date} and char position and search string length
        if self.filename is None or self.filename['id'] != next_result[0]['id']:
            self.view_file(next_result[0])
        cur.setPosition(next_result[1])
        cur.setPosition(cur.position() + next_result[2], QtGui.QTextCursor.KeepAnchor)
        self.ui.textEdit.setTextCursor(cur)
        self.ui.pushButton_search_results.setText(str(self.search_index + 1) + " / " + str(len(self.search_indices))) 
开发者ID:ccbogel,项目名称:QualCoder,代码行数:17,代码来源:code_text.py

示例11: unlight

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCursor [as 别名]
def unlight(self):
        """ Remove all text highlighting from current file. """

        if self.sourceText is None:
            return
        cursor = self.ui.textEdit.textCursor()
        cursor.setPosition(0, QtGui.QTextCursor.MoveAnchor)
        cursor.setPosition(len(self.sourceText) - 1, QtGui.QTextCursor.KeepAnchor)
        cursor.setCharFormat(QtGui.QTextCharFormat()) 
开发者ID:ccbogel,项目名称:QualCoder,代码行数:11,代码来源:code_text.py

示例12: highlight

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCursor [as 别名]
def highlight(self):
        """ Apply text highlighting to current file.
        If no colour has been assigned to a code, those coded text fragments are coloured gray.
        Each code text item contains: fid, date, pos0, pos1, seltext, cid, status, memo,
        name, owner. """

        if self.sourceText is not None:
            fmt = QtGui.QTextCharFormat()
            cursor = self.ui.textEdit.textCursor()

            # Add coding highlights
            codes = {x['cid']:x for x in self.codes}
            for item in self.code_text:
                cursor.setPosition(int(item['pos0']), QtGui.QTextCursor.MoveAnchor)
                cursor.setPosition(int(item['pos1']), QtGui.QTextCursor.KeepAnchor)
                color = codes.get(item['cid'],{}).get('color',"#F8E0E0")  # default light red
                fmt.setBackground(QtGui.QBrush(QtGui.QColor(color)))
                # Highlight codes with memos - these are italicised
                if item['memo'] is not None and item['memo'] != "":
                    fmt.setFontItalic(True)
                else:
                    fmt.setFontItalic(False)
                    fmt.setFontWeight(QtGui.QFont.Normal)
                cursor.setCharFormat(fmt)

            # Add annotation marks - these are in bold
            for note in self.annotations:
                if len(self.filename.keys()) > 0:  # will be zero if using autocode and no file is loaded
                    if note['fid'] == self.filename['id']:
                        cursor.setPosition(int(note['pos0']), QtGui.QTextCursor.MoveAnchor)
                        cursor.setPosition(int(note['pos1']), QtGui.QTextCursor.KeepAnchor)
                        formatB = QtGui.QTextCharFormat()
                        formatB.setFontWeight(QtGui.QFont.Bold)
                        cursor.mergeCharFormat(formatB) 
开发者ID:ccbogel,项目名称:QualCoder,代码行数:36,代码来源:code_text.py

示例13: eventFilter

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCursor [as 别名]
def eventFilter(self, receiver, event):
        #QtGui.QToolTip.showText(QtGui.QCursor.pos(), tip)
        if event.type() == QtCore.QEvent.ToolTip:
            helpEvent = QHelpEvent(event)
            cursor = QtGui.QTextCursor()
            cursor = receiver.cursorForPosition(helpEvent.pos())
            pos = cursor.position()
            receiver.setToolTip("")
            displayText = ""
            # Occasional None type error
            if self.code_text is None:
                #Call Base Class Method to Continue Normal Event Processing
                return super(ToolTip_EventFilter, self).eventFilter(receiver, event)
            for item in self.code_text:
                if item['pos0'] <= pos and item['pos1'] >= pos:
                    if displayText == "":
                        displayText = item['name']
                    else:  # Can have multiple codes on same selected area
                        try:
                            displayText += "\n" + item['name']
                        except Exception as e:
                            msg = "Codes ToolTipEventFilter " + str(e) + ". Possible key error: "
                            msg += str(item) + "\n" + self.code_text
                            logger.error(msg)
            if displayText != "":
                receiver.setToolTip(displayText)

        #Call Base Class Method to Continue Normal Event Processing
        return super(ToolTip_EventFilter, self).eventFilter(receiver, event) 
开发者ID:ccbogel,项目名称:QualCoder,代码行数:31,代码来源:code_text.py

示例14: unlight

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCursor [as 别名]
def unlight(self):
        """ Remove all text highlighting from current file. """

        if self.transcription is None or self.ui.textEdit.toPlainText() == "":
            return
        cursor = self.ui.textEdit.textCursor()
        cursor.setPosition(0, QtGui.QTextCursor.MoveAnchor)
        cursor.setPosition(len(self.transcription[1]) - 1, QtGui.QTextCursor.KeepAnchor)
        cursor.setCharFormat(QtGui.QTextCharFormat()) 
开发者ID:ccbogel,项目名称:QualCoder,代码行数:11,代码来源:view_av.py

示例15: eventFilter

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCursor [as 别名]
def eventFilter(self, receiver, event):
        #QtGui.QToolTip.showText(QtGui.QCursor.pos(), tip)
        if event.type() == QtCore.QEvent.ToolTip:
            helpEvent = QHelpEvent(event)
            cursor = QtGui.QTextCursor()
            cursor = receiver.cursorForPosition(helpEvent.pos())
            pos = cursor.position()
            receiver.setToolTip("")
            text = ""
            # occasional None type error
            if self.code_text is None:
                #Call Base Class Method to Continue Normal Event Processing
                return super(ToolTip_EventFilter, self).eventFilter(receiver, event)
            for item in self.code_text:
                if item['pos0'] <= pos and item['pos1'] >= pos:
                    #print(item)
                    try:
                        if text != "":
                            text = text + "\n"
                        text += item['name']  # += as can have multiple codes on same position
                        if item['avid'] is not None:
                            text += " [" + msecs_to_mins_and_secs(item['av_pos0'])
                            text += " - " + msecs_to_mins_and_secs(item['av_pos1']) + "]"
                    except Exception as e:
                        msg = "Codes ToolTipEventFilter " + str(e) + ". Possible key error: "
                        msg += str(item) + "\n" + str(self.code_text)
                        logger.error(msg)
            if text != "":
                receiver.setToolTip(text)
        #Call Base Class Method to Continue Normal Event Processing
        return super(ToolTip_EventFilter, self).eventFilter(receiver, event) 
开发者ID:ccbogel,项目名称:QualCoder,代码行数:33,代码来源:view_av.py


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