本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsView.setMouseTracking方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsView.setMouseTracking方法的具体用法?Python QGraphicsView.setMouseTracking怎么用?Python QGraphicsView.setMouseTracking使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QGraphicsView
的用法示例。
在下文中一共展示了QGraphicsView.setMouseTracking方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BoardGUI
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsView [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsView import setMouseTracking [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
#.........这里部分代码省略.........