本文整理汇总了Python中PyQt5.QtWidgets.QScrollArea.ensureVisible方法的典型用法代码示例。如果您正苦于以下问题:Python QScrollArea.ensureVisible方法的具体用法?Python QScrollArea.ensureVisible怎么用?Python QScrollArea.ensureVisible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QScrollArea
的用法示例。
在下文中一共展示了QScrollArea.ensureVisible方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GlyphCollectionWidget
# 需要导入模块: from PyQt5.QtWidgets import QScrollArea [as 别名]
# 或者: from PyQt5.QtWidgets.QScrollArea import ensureVisible [as 别名]
class GlyphCollectionWidget(QWidget):
"""
A widget that presents a list of glyphs in cells.
"""
def __init__(self, parent=None):
super(GlyphCollectionWidget, self).__init__(parent)
self.setAttribute(Qt.WA_KeyCompression)
self._glyphs = []
self._squareSize = 56
self._columns = 10
self._selection = set()
self._oldSelection = None
self._lastSelectedCell = None
self._inputString = ""
self._lastKeyInputTime = None
self.glyphSelectedCallback = None
self.doubleClickCallback = None
self.updateCurrentGlyph = False
self._maybeDragPosition = None
self.setFocusPolicy(Qt.ClickFocus)
self._currentDropIndex = None
self._scrollArea = QScrollArea(parent)
self._scrollArea.dragEnterEvent = self.pipeDragEnterEvent
self._scrollArea.dragMoveEvent = self.pipeDragMoveEvent
self._scrollArea.dragLeaveEvent = self.pipeDragLeaveEvent
self._scrollArea.dropEvent = self.pipeDropEvent
self._scrollArea.resizeEvent = self.resizeEvent
self._scrollArea.setAcceptDrops(True)
self._scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self._scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self._scrollArea.setWidget(self)
def _get_glyphs(self):
return self._glyphs
def _set_glyphs(self, glyphs):
self._glyphs = glyphs
self.adjustSize()
self.selection = set()
# self.update() # self.selection changed will do it
glyphs = property(
_get_glyphs, _set_glyphs, doc="A list of glyphs displayed. Clears "
"selection and schedules display refresh when set.")
def _get_selection(self):
return self._selection
def _set_selection(self, selection):
self._selection = selection
if not len(self._selection):
self.lastSelectedCell = None
self._computeGlyphSelection()
self.update()
selection = property(
_get_selection, _set_selection, doc="A set that contains indexes of "
"selected glyphs. Schedules display refresh when set.")
def getSelectedGlyphs(self):
return [self._glyphs[key] for key in sorted(self._selection)]
def _get_lastSelectedCell(self):
if self._lastSelectedCell is not None and \
self._lastSelectedCell >= len(self._glyphs):
return None
return self._lastSelectedCell
def _set_lastSelectedCell(self, index):
self._lastSelectedCell = index
if self.updateCurrentGlyph:
glyph = self.lastSelectedGlyph()
app = QApplication.instance()
app.setCurrentGlyph(glyph)
if index is not None:
self.scrollToCell(index)
lastSelectedCell = property(
_get_lastSelectedCell, _set_lastSelectedCell,
doc="The current lastSelectedCell in selection.")
def lastSelectedGlyph(self):
index = self.lastSelectedCell
return self._glyphs[index] if index is not None else None
def scrollArea(self):
return self._scrollArea
def scrollToCell(self, index):
x = (.5 + index % self._columns) * self.squareSize
y = (.5 + index // self._columns) * self.squareSize
self._scrollArea.ensureVisible(
x, y, .5 * self.squareSize, .5 * self.squareSize)
def _get_currentDropIndex(self):
return self._currentDropIndex
#.........这里部分代码省略.........
示例2: GlyphCollectionWidget
# 需要导入模块: from PyQt5.QtWidgets import QScrollArea [as 别名]
# 或者: from PyQt5.QtWidgets.QScrollArea import ensureVisible [as 别名]
class GlyphCollectionWidget(QWidget):
def __init__(self, parent=None):
super(GlyphCollectionWidget, self).__init__(parent)
self.setAttribute(Qt.WA_KeyCompression)
self._glyphs = []
# TODO: hide behind a façade
self.squareSize = 56
self._columns = 10
self._selection = set()
self._oldSelection = None
self._lastSelectedCell = None
self.characterSelectedCallback = None
self.doubleClickCallback = None
self.updateCurrentGlyph = False
self._maybeDragPosition = None
self.setFocusPolicy(Qt.ClickFocus)
self._currentDropIndex = None
self._scrollArea = QScrollArea(parent)
self._scrollArea.dragEnterEvent = self.pipeDragEnterEvent
self._scrollArea.dragMoveEvent = self.pipeDragMoveEvent
self._scrollArea.dragLeaveEvent = self.pipeDragLeaveEvent
self._scrollArea.dropEvent = self.pipeDropEvent
self._scrollArea.setAcceptDrops(True)
self._scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self._scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self._scrollArea.setWidget(self)
def _get_glyphs(self):
return self._glyphs
def _set_glyphs(self, glyphs):
self._glyphs = glyphs
self.adjustSize()
self.selection = set()
#self.update() # self.selection changed will do it
glyphs = property(_get_glyphs, _set_glyphs, doc="A list of glyphs \
displayed. Clears selection and schedules display refresh when set.")
def _get_selection(self):
return self._selection
def _set_selection(self, selection):
self._selection = selection
self.computeCharacterSelected()
self.update()
selection = property(_get_selection, _set_selection, doc="A set that contains \
indexes of selected glyphs. Schedules display refresh when set.")
def getSelectedGlyphs(self):
return [self._glyphs[key] for key in sorted(self._selection)]
def _get_lastSelectedCell(self):
return self._lastSelectedCell
def _set_lastSelectedCell(self, index):
self._lastSelectedCell = index
if self.updateCurrentGlyph:
glyph = self.lastSelectedGlyph()
app = QApplication.instance()
app.setCurrentGlyph(glyph)
if index is not None:
self.scrollToCell(index)
lastSelectedCell = property(_get_lastSelectedCell, _set_lastSelectedCell,
doc="The current lastSelectedCell in selection.")
def lastSelectedGlyph(self):
index = self._lastSelectedCell
return self._glyphs[index] if index is not None else None
def scrollArea(self):
return self._scrollArea
def scrollToCell(self, index):
x = (.5 + index % self._columns) * self.squareSize
y = (.5 + index // self._columns) * self.squareSize
self._scrollArea.ensureVisible(x, y, .5*self.squareSize, .5*self.squareSize)
def _get_currentDropIndex(self):
return self._currentDropIndex
def _set_currentDropIndex(self, index):
self._currentDropIndex = index
self.update()
currentDropIndex = property(_get_currentDropIndex, _set_currentDropIndex)
def pipeDragEnterEvent(self, event):
# glyph reordering
if event.source() == self:
event.acceptProposedAction()
def pipeDragMoveEvent(self, event):
if event.source() == self:
pos = event.posF()
self.currentDropIndex = int(self._columns * (pos.y() // self.squareSize) \
#.........这里部分代码省略.........
示例3: GlyphsCanvas
# 需要导入模块: from PyQt5.QtWidgets import QScrollArea [as 别名]
# 或者: from PyQt5.QtWidgets.QScrollArea import ensureVisible [as 别名]
#.........这里部分代码省略.........
self.descender = self.font.info.descender
if self.descender is None:
self.descender = 250
self.upm = self.font.info.unitsPerEm
if self.upm is None or not self.upm > 0:
self.upm = 1000
def setGlyphs(self, newGlyphs):
self.glyphs = newGlyphs
self._selected = None
self.adjustSize()
self.update()
def setPointSize(self, pointSize):
self.ptSize = int(pointSize)
self.calculateScale()
self.adjustSize()
self.update()
def setSelected(self, selected):
self._selected = selected
if self._positions is not None:
cur_len = 0
line = -1
for index, li in enumerate(self._positions):
if cur_len + len(li) > self._selected:
pos, width = li[self._selected - cur_len]
line = index
break
cur_len += len(li)
if line > -1:
x = self.padding + pos + width / 2
y = self.padding + (line + .5) * self.ptSize * self._lineHeight
self._scrollArea.ensureVisible(
x, y, width / 2 + 20,
.5 * self.ptSize * self._lineHeight + 20)
self.update()
def _calcPaintWidthHeight(self):
cur_width = 0
max_width = 0
lines = 1
self._positions = [[]]
for index, glyph in enumerate(self.glyphs):
# line wrapping
gWidth = glyph.width * self.scale
doKern = index > 0 and self._showKerning and cur_width > 0
if doKern:
kern = self.lookupKerningValue(
self.glyphs[index - 1].name, glyph.name) * self.scale
else:
kern = 0
if (self._wrapLines and cur_width + gWidth + kern +
2 * self.padding > self.width()) or glyph.unicode == 2029:
self._positions.append([(0, gWidth)])
cur_width = gWidth
lines += 1
else:
self._positions[-1].append((cur_width, gWidth))
cur_width += gWidth + kern
max_width = max(cur_width, max_width)
return (max_width + self.padding * 2,
lines * self.ptSize * self._lineHeight + 2 * self.padding)
def sizeHint(self):