本文整理汇总了Python中PyQt5.QtWidgets.QScrollArea.viewport方法的典型用法代码示例。如果您正苦于以下问题:Python QScrollArea.viewport方法的具体用法?Python QScrollArea.viewport怎么用?Python QScrollArea.viewport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QScrollArea
的用法示例。
在下文中一共展示了QScrollArea.viewport方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GlyphsCanvas
# 需要导入模块: from PyQt5.QtWidgets import QScrollArea [as 别名]
# 或者: from PyQt5.QtWidgets.QScrollArea import viewport [as 别名]
#.........这里部分代码省略.........
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):
innerWidth = self._scrollArea.viewport().width()
innerHeight = self._scrollArea.viewport().height()
paintWidth, paintHeight = self._calcPaintWidthHeight()
return QSize(
max(innerWidth, paintWidth),
max(innerHeight, paintHeight))
def resizeEvent(self, event):
maxHeight = max(self._scrollArea.viewport().height(), self.height())
if self._wrapLines:
self.resize(self._scrollArea.viewport().width(), maxHeight)
else:
maxWidth = max(self._scrollArea.viewport().width(), self.width())
self.resize(maxWidth, maxHeight)
def wheelEvent(self, event):
if event.modifiers() & Qt.ControlModifier:
# TODO: should it snap to predefined pointSizes?
# is the scaling factor okay?
# XXX: current alg. is not reversible...
decay = event.angleDelta().y() / 120.0
scale = round(self.ptSize / 10)
if scale == 0 and decay >= 0:
scale = 1
newPointSize = self.ptSize + int(decay) * scale
if newPointSize <= 0:
return
self.setPointSize(newPointSize)
if self.pointSizeChangedCallback is not None:
self.pointSizeChangedCallback(newPointSize)
event.accept()
else:
示例2: GlyphCollectionWidget
# 需要导入模块: from PyQt5.QtWidgets import QScrollArea [as 别名]
# 或者: from PyQt5.QtWidgets.QScrollArea import viewport [as 别名]
#.........这里部分代码省略.........
def pipeDropEvent(self, event):
# TODO: consider dropping this check, maybe only subclasses should do
# it so as to dispatch but here we presumably don't need it
# TODO: shouldn't this mutate font.glyphOrder
if event.source() == self:
insert = self.currentDropIndex
newGlyphNames = event.mimeData().text().split(" ")
font = self._glyphs[0].font
# TODO: should glyphOrder change activate font.dirty?
newGlyphs = [font[name] for name in newGlyphNames]
# put all glyphs to be moved to None (deleting them would
# invalidate our insert indexes)
for index, glyph in enumerate(self._glyphs):
if glyph in newGlyphs:
self._glyphs[index] = None
# insert newGlyphs into the list
lst = self._glyphs[:insert]
lst.extend(newGlyphs + self._glyphs[insert:])
self._glyphs = lst
# now, elide None
self.currentDropIndex = None
self.glyphs = [glyph
for glyph in self._glyphs if glyph is not None]
# update glyphOrder
# TODO: remove dep on parent
font.disableNotifications("Font.GlyphOrderChanged", self.parent())
font.glyphOrder = [glyph.name for glyph in self._glyphs]
font.enableNotifications("Font.GlyphOrderChanged", self.parent())
def resizeEvent(self, event):
self._rewindColumns()
def _rewindColumns(self):
columns = self._scrollArea.viewport().width() // self.squareSize
if not columns > 0:
return
self._columns = columns
self.adjustSize()
def sizeHint(self):
# Calculate sizeHint with max(height, _scrollArea.height()) because
# if scrollArea is bigger than widget height after an update, we risk
# leaving old painted content on screen
return QSize(
self._columns * self.squareSize,
max(math.ceil(len(self._glyphs) / self._columns) * self.squareSize,
self._scrollArea.height()))
# TODO: consider moving this to caller, it isn't specific to this widget
def _computeGlyphSelection(self):
if self.glyphSelectedCallback is None:
return
cnt = len(self.selection)
if cnt == 1:
elem = next(iter(self.selection))
self.glyphSelectedCallback(self._glyphs[elem].name)
else:
self.glyphSelectedCallback(cnt)
def _arrowKeyPressEvent(self, event):
count = event.count()
key = event.key()
modifiers = event.modifiers()
# TODO: it might be the case that self._lastSelectedCell cannot be None
# when we arrive here whatsoever
if self.lastSelectedCell is not None:
示例3: GlyphView
# 需要导入模块: from PyQt5.QtWidgets import QScrollArea [as 别名]
# 或者: from PyQt5.QtWidgets.QScrollArea import viewport [as 别名]
class GlyphView(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self._currentTool = BaseTool()
self._mouseDown = False
self._glyph = None
# drawing attributes
self._layerDrawingAttributes = {}
self._fallbackDrawingAttributes = dict(
showGlyphFill=False,
showGlyphStroke=True,
showGlyphOnCurvePoints=True,
showGlyphStartPoints=True,
showGlyphOffCurvePoints=True,
showGlyphPointCoordinates=False,
showGlyphAnchors=True,
showGlyphImage=False,
showGlyphMargins=True,
showFontVerticalMetrics=True,
showFontVerticalMetricsTitles=True,
showFontPostscriptBlues=False,
showFontPostscriptFamilyBlues=False,
)
# cached vertical metrics
self._unitsPerEm = 1000
self._descender = -250
self._capHeight = 750
self._ascender = 750
# drawing data cache
self._drawingRect = None
self._scale = 1.0
self._inverseScale = 0.1
self._impliedPointSize = 1000
# drawing calculation
self._centerVertically = True
self._centerHorizontally = True
self._noPointSizePadding = 200
self._verticalCenterYBuffer = 0
# insert scrollArea
self.setFocusPolicy(Qt.ClickFocus)
self._scrollArea = QScrollArea(parent)
self._scrollArea.resizeEvent = self.resizeEvent
self._scrollArea.setWidget(self)
# --------------
# Custom Methods
# --------------
def _getGlyphWidthHeight(self):
if self._glyph is None:
return 0, 0
bottom = self._descender
top = max(self._capHeight, self._ascender,
self._unitsPerEm + self._descender)
width = self._glyph.width
height = -bottom + top
return width, height
def fitScaleMetrics(self):
fitHeight = self._scrollArea.viewport().height()
_, glyphHeight = self._getGlyphWidthHeight()
glyphHeight += self._noPointSizePadding * 2
self.setScale(fitHeight / glyphHeight)
def fitScaleBBox(self):
if self._glyph is None:
return
if self._glyph.bounds is None:
self.fitScaleMetrics()
return
_, bottom, _, top = self._glyph.bounds
fitHeight = self._scrollArea.viewport().height()
glyphHeight = top - bottom
glyphHeight += self._noPointSizePadding * 2
self.setScale(fitHeight / glyphHeight)
def inverseScale(self):
return self._inverseScale
def scale(self):
return self._scale
def setScale(self, scale):
self._scale = scale
if self._scale <= 0:
self._scale = .01
self._inverseScale = 1.0 / self._scale
self._impliedPointSize = self._unitsPerEm * self._scale
def glyph(self):
return self._glyph
def setGlyph(self, glyph):
# TODO: disable/enable there makes sense, right?
#.........这里部分代码省略.........