本文整理汇总了Python中PyQt5.QtWidgets.QStackedLayout.setSpacing方法的典型用法代码示例。如果您正苦于以下问题:Python QStackedLayout.setSpacing方法的具体用法?Python QStackedLayout.setSpacing怎么用?Python QStackedLayout.setSpacing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QStackedLayout
的用法示例。
在下文中一共展示了QStackedLayout.setSpacing方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CodeCompletionWidget
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import setSpacing [as 别名]
class CodeCompletionWidget(QFrame):
def __init__(self, editor):
super(CodeCompletionWidget, self).__init__(
None, Qt.FramelessWindowHint | Qt.ToolTip)
self._editor = editor
self._revision = 0
self._block = 0
self.stack_layout = QStackedLayout(self)
self.stack_layout.setContentsMargins(0, 0, 0, 0)
self.stack_layout.setSpacing(0)
self.completion_list = QListWidget()
self.completion_list.setMinimumHeight(200)
self.completion_list.setAlternatingRowColors(True)
self._list_index = self.stack_layout.addWidget(self.completion_list)
self._icons = {'a': resources.IMAGES['attribute'],
'f': resources.IMAGES['function'],
'c': resources.IMAGES['class'],
'm': resources.IMAGES['module']}
self.cc = code_completion.CodeCompletion()
self._completion_results = {}
self._prefix = ''
self.setVisible(False)
self.source = ''
self._key_operations = {
Qt.Key_Up: self._select_previous_row,
Qt.Key_Down: self._select_next_row,
Qt.Key_PageUp: (lambda: self._select_previous_row(6)),
Qt.Key_PageDown: (lambda: self._select_next_row(6)),
Qt.Key_Right: lambda: None,
Qt.Key_Left: lambda: None,
Qt.Key_Enter: self.pre_key_insert_completion,
Qt.Key_Return: self.pre_key_insert_completion,
Qt.Key_Tab: self.pre_key_insert_completion,
Qt.Key_Space: self.hide_completer,
Qt.Key_Escape: self.hide_completer,
Qt.Key_Backtab: self.hide_completer,
Qt.NoModifier: self.hide_completer,
Qt.ShiftModifier: self.hide_completer,
}
self.desktop = QApplication.instance().desktop()
self.completion_list.itemClicked['QListWidgetItem*'].connect(self.pre_key_insert_completion)
self._editor.document().cursorPositionChanged['const QTextCursor &'].connect(self.update_metadata)
def _select_next_row(self, move=1):
new_row = self.completion_list.currentRow() + move
if new_row < self.completion_list.count():
self.completion_list.setCurrentRow(new_row)
else:
self.completion_list.setCurrentRow(0)
return True
def _select_previous_row(self, move=1):
new_row = self.completion_list.currentRow() - move
if new_row >= 0:
self.completion_list.setCurrentRow(new_row)
else:
self.completion_list.setCurrentRow(
self.completion_list.count() - move)
return True
def update_metadata(self, cursor):
if settings.CODE_COMPLETION:
if self._editor.document().revision() != self._revision and \
cursor.block().blockNumber() != self._block:
source = self._editor.get_text()
source = source.encode(self._editor.encoding)
self.cc.analyze_file(self._editor.ID, source,
self._editor.indent, self._editor.useTabs)
self._revision = self._editor.document().revision()
self._block = cursor.block().blockNumber()
def insert_completion(self, insert, type_=ord('a')):
if insert != self._prefix:
closing = ''
if type_ in (ord('f'), ord('c')):
closing = '()'
extra = len(self._prefix) - len(insert)
insertion = '%s%s' % (insert[extra:], closing)
self._editor.textCursor().insertText(insertion)
self.hide_completer()
def _get_geometry(self):
cr = self._editor.cursorRect()
desktop_geometry = self.desktop.availableGeometry(self._editor)
point = self._editor.mapToGlobal(cr.topLeft())
cr.moveTopLeft(point)
#Check new position according desktop geometry
width = (self.completion_list.sizeHintForColumn(0) +
self.completion_list.verticalScrollBar().sizeHint().width() +
10)
height = 200
orientation = (point.y() + height) < desktop_geometry.height()
if orientation:
cr.moveTop(cr.bottom())
cr.setWidth(width)
#.........这里部分代码省略.........