本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsView.setViewportUpdateMode方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsView.setViewportUpdateMode方法的具体用法?Python QGraphicsView.setViewportUpdateMode怎么用?Python QGraphicsView.setViewportUpdateMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QGraphicsView
的用法示例。
在下文中一共展示了QGraphicsView.setViewportUpdateMode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BoardGUI
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsView [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsView import setViewportUpdateMode [as 别名]
class BoardGUI(QWidget):
"""cointain the graphical representation of the Board"""
# ratio of bordersize compared to the size of one base square
borderRatio = 0.8
baseRectRatio = 14/15 # 12/13 for normal ratio but looks weird
stoneScale = 0.46
# siganl
stoneClicked = pyqtSignal(tuple)
def __init__(self, parent, game):
super().__init__()
self.initUI(game)
def initUI(self, game):
self.board = game.currentBoard
self.game = game
self.showCoords = True
self.scene = QGraphicsScene()
# grid containing coordinates for the scene
self.grid = []
self.drawGrid()
# initialize and set layout + view
self.view = QGraphicsView(self.scene)
self.view.setMouseTracking(True)
self.view.setViewportUpdateMode(QGraphicsView.FullViewportUpdate)
self.setMouseTracking(True)
box = QHBoxLayout()
box.addWidget(self.view)
self.setLayout(box)
# stones for all positions are created and listed in self.pos dict
self.createPosition()
self.makeCoords() # has to be called after drawGrid!
def resizeEvent(self, e):
self.view.fitInView(self.view.scene().sceneRect(), Qt.KeepAspectRatio)
def boardWidth(self):
"""returns the max width fitting into widget"""
width = self.contentsRect().width()*0.95
height = self.contentsRect().height()*0.95
return min(width, height*self.baseRectRatio)
def boardHeight(self):
"""returns the max width fitting into widget """
return self.boardWidth()*(1/self.baseRectRatio)
def makeGrid(self):
"""
returns coords [[(x, y)]] for the Grid according
to current window mesures
"""
# set scenesize to window size
self.scene.setSceneRect(0, 0, self.boardWidth(), self.boardHeight())
denom = self.board.size + 2*self.borderRatio
baseWidth = self.boardWidth() / denom
baseHeight = self.boardHeight() / denom
leftOffset = 0.5*baseWidth # (self.contentsRect().width()-self.boardWidth())/2
topOffset = 0 # (self.contentsRect().height()-self.boardHeight())/2
partionWidth = [leftOffset+(self.borderRatio+x)*baseWidth
for x in range(self.board.size)]
partionHeight = [topOffset+(self.borderRatio+x)*baseHeight
for x in range(self.board.size)]
grid = [[(x, y) for x in partionWidth] for y in partionHeight]
self.grid = grid
self.baseWidth = baseWidth
def drawGrid(self):
"""draws the background grid"""
self.makeGrid()
for line in self.grid:
self.scene.addLine(*line[0], *line[-1])
for (pointT, pointB) in zip(self.grid[0], self.grid[-1]):
self.scene.addLine(*pointT, *pointB)
self.drawHoshis()
def makeCoords(self):
""" draws Coordinates """
xLabels = "ABCDEFGHIKLMNOPQRSTUVWXYZ"
yLabels = list(range(1, 26))
botGrid = []
leftGrid = []
# generate pixel coordinates grids
for n in range(self.board.size):
(xBot, yBot) = self.grid[self.board.size-1][n]
yBot += self.baseWidth*0.4/self.baseRectRatio
xBot -= self.baseWidth*0.1
botGrid.append((xBot, yBot))
(xLeft, yLeft) = self.grid[n][0]
xLeft -= self.baseWidth*1.2
#.........这里部分代码省略.........
示例2: QApplication
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsView [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsView import setViewportUpdateMode [as 别名]
import sys
app = QApplication(sys.argv)
scene = QGraphicsScene()
scene.setStickyFocus(True)
for y in range(10):
for x in range(10):
proxy = CustomProxy(None, Qt.Window)
proxy.setWidget(EmbeddedDialog())
rect = proxy.boundingRect()
proxy.setPos( x * rect.width()*1.05, y*rect.height()*1.05 )
proxy.setCacheMode(QGraphicsItem.DeviceCoordinateCache)
scene.addItem(proxy)
scene.setSceneRect(scene.itemsBoundingRect())
view = QGraphicsView(scene)
view.scale(0.5, 0.5)
view.setRenderHints(view.renderHints() | QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
view.setBackgroundBrush(QBrush(QPixmap(':/No-Ones-Laughing-3.jpg')))
view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate)
view.show()
view.setWindowTitle("Embedded Dialogs Demo")
sys.exit(app.exec_())
示例3: ClassDiagram
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsView [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsView import setViewportUpdateMode [as 别名]
class ClassDiagram(QWidget, itab_item.ITabItem):
def __init__(self, actions, parent=None):
super(ClassDiagram, self).__init__(parent)
self.actions = actions
self.graphicView = QGraphicsView(self)
self.scene = QGraphicsScene()
self.graphicView.setScene(self.scene)
self.graphicView.setViewportUpdateMode(
QGraphicsView.BoundingRectViewportUpdate)
vLayout = QVBoxLayout(self)
self.setLayout(vLayout)
vLayout.addWidget(self.graphicView)
self.scene.setItemIndexMethod(QGraphicsScene.NoIndex)
self.scene.setSceneRect(-200, -200, 400, 400)
self.graphicView.setMinimumSize(400, 400)
actualProject = self.actions.ide.explorer.get_actual_project()
arrClasses = self.actions._locator.get_classes_from_project(
actualProject)
#FIXME:dirty need to fix
self.mX = -400
self.mY = -320
self.hightestY = self.mY
filesList = []
for elem in arrClasses:
#loking for paths
filesList.append(elem[2])
for path in set(filesList):
self.create_class(path)
def create_class(self, path):
content = file_manager.read_file_content(path)
items = introspection.obtain_symbols(content)
mYPadding = 10
mXPadding = 10
for classname, classdetail in list(items["classes"].items()):
cl = ClassModel(self.graphicView, self.scene)
cl.set_class_name(classname)
self.fill_clases(cl, classdetail[1])
self.scene.addItem(cl)
cl.setPos(self.mX, self.mY)
self.mX += cl._get_width() + mXPadding
if self.hightestY < self.mY + cl.get_height():
self.hightestY = self.mY + cl.get_height()
if self.mX > 2000:
self.mX = -400
self.mY += self.hightestY + mYPadding
def fill_clases(self, classComponent, classContent):
funct = classContent['functions']
classComponent.set_functions_list(funct)
attr = classContent['attributes']
classComponent.set_attributes_list(attr)
def scale_view(self, scaleFactor):
factor = self.graphicView.transform().scale(
scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width()
if factor > 0.05 and factor < 15:
self.graphicView.scale(scaleFactor, scaleFactor)
def keyPressEvent(self, event):
taskList = {
Qt.Key_Plus: lambda: self.scaleView(1.2),
Qt.Key_Minus: lambda: self.scaleView(1 / 1.2)}
if(event.key() in taskList):
taskList[event.key()]()
else:
QWidget.keyPressEvent(self, event)