本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsScene.itemsBoundingRect方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsScene.itemsBoundingRect方法的具体用法?Python QGraphicsScene.itemsBoundingRect怎么用?Python QGraphicsScene.itemsBoundingRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QGraphicsScene
的用法示例。
在下文中一共展示了QGraphicsScene.itemsBoundingRect方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_ui
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsScene [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsScene import itemsBoundingRect [as 别名]
def init_ui(self):
scene = QGraphicsScene()
scene.setBackgroundBrush(QColor(100, 100, 100))
scene.setItemIndexMethod(QGraphicsScene.BspTreeIndex)
scene.setSceneRect(scene.itemsBoundingRect())
self.setDragMode(QGraphicsView.RubberBandDrag)
self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate)
self.setRenderHints(QPainter.Antialiasing | QPainter.TextAntialiasing)
self.frame_item = QGraphicsPixmapItem()
self.text_item_offset = 0
self.rect_item_array = []
self.text_item_array = []
for i in range(0, 5):
rect_item = QGraphicsRectItem()
rect_item.setVisible(False)
rect_item.setZValue(20.0)
rect_item.setPen(QPen(Qt.red, 5))
rect_item.setRect(20, 20, 20, 20)
scene.addItem(rect_item)
self.rect_item_array.append(rect_item)
text_item = QGraphicsSimpleTextItem("")
text_item.setBrush(QBrush(Qt.red))
text_item.setZValue(20.0)
text_item.setPos(10, 50)
text_item.setFont(QFont("黑体", 24))
text_item.setVisible(False)
scene.addItem(text_item)
self.text_item_array.append(text_item)
scene.addItem(self.frame_item)
self.curr_factor = 1.0
self.setScene(scene)
示例2: GuiAnalysisVisualization
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsScene [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsScene import itemsBoundingRect [as 别名]
#.........这里部分代码省略.........
def setScene(self):
self.scene = QGraphicsScene()
# self.scene.setSceneRect(0, 0, 600, 1000)
pass
def add_toolbar(self, toolbar_name):
_toolbar = self.addToolBar(toolbar_name)
self._toolbars[toolbar_name] = _toolbar
def add_fuction_to_toolbar(self, toolbar_name, _callable):
assert callable(_callable), "the function supplied is not callable"
try:
_action = QtWidgets.QAction(_callable.__name__.replace('_', ' ').lower(), self)
_action.triggered.connect(_callable)
self._toolbars[toolbar_name].addSeparator()
self._toolbars[toolbar_name].addAction(_action)
except KeyError:
raise ValueError("the value %s toolbar does not exist" % toolbar_name)
def setup_toolbar(self):
self.add_toolbar("Main Toolbar")
self.add_fuction_to_toolbar("Main Toolbar", self.add_clearance_width_graph)
self.add_fuction_to_toolbar("Main Toolbar", self.add_clearance_height_graph)
self.add_fuction_to_toolbar("Main Toolbar", self.add_surface_graph)
self.add_fuction_to_toolbar("Main Toolbar", self.export_image)
def export_image(self):
# print f.Export("tetesdrf.svg", Graphic3d_EF_SVG)
'''root = Tk()
root.withdraw()
file_name = tkinter.filedialog.asksaveasfile(filetypes=[("PNG files", "*.png")])
name = str(file_name)+".png"
root.destroy()'''
self.scene.setSceneRect(self.scene.itemsBoundingRect())
image = QImage(self.scene.sceneRect().size().toSize(), QImage.Format_RGB32)
painter = QPainter(image)
painter.setRenderHint(QPainter.Antialiasing)
self.scene.render(painter)
print(image.save("0002_export_analysis.png"))
def add_clearance_width_graph(self):
y_pos = self.get_y_pos()
x_pos = 0
clearance_width_graph = ClearanceWidthGraph(self, x_pos, y_pos, "dimension width")
self.graphics.append(clearance_width_graph)
# self.scene.addItem(clearance_width_graph)
for item in clearance_width_graph.items:
self.scene.addItem(item)
print("clearance_weight_graph_added")
def add_clearance_height_graph(self):
y_pos = self.get_y_pos()
x_pos = 0
clearance_height_graph = ClearanceHeightGraph(self, x_pos, y_pos, "dimension height")
self.graphics.append(clearance_height_graph)
# self.scene.addItem(clearance_height_graph)
for item in clearance_height_graph.items:
self.scene.addItem(item)
print("clearance_height_graph_added")
pass
def add_surface_graph(self):
y_pos = self.get_y_pos()
x_pos = 0
示例3: __init__
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsScene [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsScene import itemsBoundingRect [as 别名]
#.........这里部分代码省略.........
frontState.assignProperty(selectionItem, "visible", True)
backState.assignProperty(pad, "fill", True)
backState.assignProperty(backItem, "visible", True)
backState.assignProperty(xRotation, "angle", 0.0)
backState.assignProperty(yRotation, "angle", 0.0)
backState.assignProperty(flipRotation, "angle", 180.0)
backState.assignProperty(selectionItem, "visible", False)
stateMachine.addDefaultAnimation(smoothXRotation)
stateMachine.addDefaultAnimation(smoothYRotation)
stateMachine.addDefaultAnimation(smoothXSelection)
stateMachine.addDefaultAnimation(smoothYSelection)
stateMachine.setInitialState(splashState)
anyKeyTransition = QEventTransition(self, QEvent.KeyPress, splashState)
anyKeyTransition.setTargetState(frontState)
anyKeyTransition.addAnimation(smoothSplashMove)
anyKeyTransition.addAnimation(smoothSplashOpacity)
enterTransition = QKeyEventTransition(self, QEvent.KeyPress,
Qt.Key_Enter, backState)
returnTransition = QKeyEventTransition(self, QEvent.KeyPress,
Qt.Key_Return, backState)
backEnterTransition = QKeyEventTransition(self, QEvent.KeyPress,
Qt.Key_Enter, frontState)
backReturnTransition = QKeyEventTransition(self, QEvent.KeyPress,
Qt.Key_Return, frontState)
enterTransition.setTargetState(historyState)
returnTransition.setTargetState(historyState)
backEnterTransition.setTargetState(backState)
backReturnTransition.setTargetState(backState)
enterTransition.addAnimation(flipAnimation)
returnTransition.addAnimation(flipAnimation)
backEnterTransition.addAnimation(flipAnimation)
backReturnTransition.addAnimation(flipAnimation)
columns = size.width()
rows = size.height()
stateGrid = []
for y in range(rows):
stateGrid.append([QState(frontState) for _ in range(columns)])
frontState.setInitialState(stateGrid[0][0])
selectionItem.setPos(pad.iconAt(0, 0).pos())
for y in range(rows):
for x in range(columns):
state = stateGrid[y][x]
rightTransition = QKeyEventTransition(self, QEvent.KeyPress,
Qt.Key_Right, state)
leftTransition = QKeyEventTransition(self, QEvent.KeyPress,
Qt.Key_Left, state)
downTransition = QKeyEventTransition(self, QEvent.KeyPress,
Qt.Key_Down, state)
upTransition = QKeyEventTransition(self, QEvent.KeyPress,
Qt.Key_Up, state)
rightTransition.setTargetState(stateGrid[y][(x + 1) % columns])
leftTransition.setTargetState(stateGrid[y][((x - 1) + columns) % columns])
downTransition.setTargetState(stateGrid[(y + 1) % rows][x])
upTransition.setTargetState(stateGrid[((y - 1) + rows) % rows][x])
icon = pad.iconAt(x, y)
state.assignProperty(xRotation, "angle", -icon.x() / 6.0)
state.assignProperty(yRotation, "angle", icon.y() / 6.0)
state.assignProperty(selectionItem, "x", icon.x())
state.assignProperty(selectionItem, "y", icon.y())
frontState.assignProperty(icon, "visible", True)
backState.assignProperty(icon, "visible", False)
setIconVisibleAnimation = QPropertyAnimation(icon, b'visible')
setIconVisibleAnimation.setDuration(0)
setVariablesSequence.addAnimation(setIconVisibleAnimation)
scene = QGraphicsScene(self)
scene.setBackgroundBrush(QBrush(QPixmap(":/images/blue_angle_swirl.jpg")))
scene.setItemIndexMethod(QGraphicsScene.NoIndex)
scene.addItem(pad)
scene.setSceneRect(scene.itemsBoundingRect())
self.setScene(scene)
sbr = splash.boundingRect()
splash.setPos(-sbr.width() / 2, scene.sceneRect().top() - 2)
frontState.assignProperty(splash, "y", splash.y() - 100.0)
scene.addItem(splash)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setMinimumSize(50, 50)
self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate)
self.setCacheMode(QGraphicsView.CacheBackground)
self.setRenderHints(QPainter.Antialiasing |
QPainter.SmoothPixmapTransform | QPainter.TextAntialiasing)
if QGLFormat.hasOpenGL():
self.setViewport(QGLWidget(QGLFormat(QGL.SampleBuffers)))
stateMachine.start()
示例4: QApplication
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsScene [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsScene import itemsBoundingRect [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_())
示例5: TrainerDialog
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsScene [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsScene import itemsBoundingRect [as 别名]
class TrainerDialog(QDialog, Ui_Trainer):
scene = None
data_manager = None
tooth1 = None
tooth2 = None
align_step = 0
pca = None
trained = pyqtSignal(PCA)
def __init__(self, data_manager):
super(TrainerDialog, self).__init__()
self.setupUi(self)
self.setAttribute(Qt.WA_DeleteOnClose)
self.scene = QGraphicsScene()
self.scene.setBackgroundBrush(QBrush(QColor.fromRgb(50, 50, 50)))
self.graphicsView.setScene(self.scene)
self.alignButton.clicked.connect(self.make_step)
self.trainButton.clicked.connect(self.train)
assert isinstance(data_manager, DataManager)
self.data_manager = data_manager
self.change_teeth(1)
teeth = data_manager.get_all_teeth(False)
self.choiceSlider.setRange(1, len(teeth) - 1)
self.choiceSlider.valueChanged.connect(self.change_teeth)
def change_teeth(self, idx):
teeth = self.data_manager.get_all_teeth(True)
self.tooth1 = teeth[0]
self.tooth2 = teeth[idx]
self.tooth1.outline_pen = QPen(QColor.fromRgb(255, 0, 0))
self.tooth2.outline_pen = QPen(QColor.fromRgb(0, 255, 0))
self.scene.clear()
self.tooth1.draw(self.scene, True, False, False)
self.tooth2.draw(self.scene, True, False, False)
self._focus_view()
self.align_step = 0
def make_step(self):
if self.align_step == 3:
return
if self.align_step == 0:
self.tooth1.move_to_origin()
self.tooth2.move_to_origin()
if self.align_step == 1:
self.tooth1.normalize_shape()
self.tooth2.normalize_shape()
self.tooth1.outline_pen.setWidthF(0.02)
self.tooth2.outline_pen.setWidthF(0.02)
if self.align_step == 2:
self.tooth2.align(self.tooth1)
self.scene.clear()
self.tooth1.draw(self.scene, True, False, False)
self.tooth2.draw(self.scene, True, False, False)
self._focus_view()
self.align_step += 1
def _focus_view(self):
rect = self.scene.itemsBoundingRect()
self.scene.setSceneRect(rect)
self.graphicsView.fitInView(rect, Qt.KeepAspectRatio)
def train(self):
self.pca = StatisticalShapeModel.create(self.data_manager)
self.pca.threshold(self.thresholdSpinBox.value())
self._show_training_result()
self.trained.emit(self.pca)
def _show_training_result(self):
mean_tooth = Tooth(to_landmarks_format(self.pca.mean))
test_tooth = self.data_manager.get_tooth(0, 0, True)
test_tooth.align(mean_tooth)
tooth_data = test_tooth.landmarks.flatten()
projection = self.pca.project(tooth_data)
reconstructed_data = self.pca.reconstruct(projection)
shapes = [self.pca.mean, tooth_data, reconstructed_data]
colors = [[255, 0, 0], [0, 255, 255], [255, 255, 0]]
self.scene.clear()
for i, shape in enumerate(shapes):
tooth = Tooth(to_landmarks_format(shape))
r, g, b = colors[i]
tooth.outline_pen = QPen(QColor.fromRgb(r, g, b))
tooth.outline_pen.setWidthF(0.02)
tooth.draw(self.scene, True, False, False)
#.........这里部分代码省略.........