本文整理汇总了Python中scene.Scene.setSceneRect方法的典型用法代码示例。如果您正苦于以下问题:Python Scene.setSceneRect方法的具体用法?Python Scene.setSceneRect怎么用?Python Scene.setSceneRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scene.Scene
的用法示例。
在下文中一共展示了Scene.setSceneRect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Controller
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import setSceneRect [as 别名]
#.........这里部分代码省略.........
def slotColorChanged(self, color):
shapes = self.selectedShapes()
if shapes:
for shape in shapes:
shape.settings.setColor(color)
else:
self.scene.newShapeSettings.setColor(color)
def slotThicknessChanged(self, thickness):
shapes = self.selectedShapes()
if shapes:
for shape in shapes:
shape.settings.setThickness(thickness)
else:
self.scene.newShapeSettings.setThickness(thickness)
def show(self):
self.window.show()
def open(self):
name = QFileDialog.getOpenFileName(self.window, self.tr("Open Image"))
if name.isEmpty():
return
self.load(name)
def grabScreenshot(self):
pos = self.window.pos()
self.window.hide()
try:
pix = grab.showDialog()
if pix is not None:
self.setPixmap(pix)
finally:
self.window.show()
self.window.move(pos)
KWindowSystem.forceActiveWindow(self.window.winId())
def save(self):
name = QFileDialog.getSaveFileName(self.window, self.tr("Save Image as"))
if name.isEmpty():
return
image = self.imageFromScene()
ok = image.save(name)
if not ok:
KMessageBox.error(self.window, self.tr("Failed to save image as %1").arg(name));
def imageFromScene(self):
# Hide elements we don't want to show
selection = self.scene.selectedItems()
self.scene.clearSelection()
self.pixmapItem.setHandlesVisible(False)
# Render
rect = self.scene.itemsBoundingRect()
image = QImage(int(rect.width()), int(rect.height()), QImage.Format_ARGB32)
image.fill(Qt.transparent)
painter = QPainter(image)
painter.setRenderHint(QPainter.Antialiasing)
self.scene.render(painter, QRectF(image.rect()), rect)
painter.end()
# Restore hidden elements
for item in selection:
item.setSelected(True)
self.pixmapItem.setHandlesVisible(True)
return image
def load(self, fileName):
self.setPixmap(QPixmap(fileName))
def setPixmap(self, pix):
self.pixmapItem.setPixmap(pix)
self.scene.setSceneRect(QRectF(pix.rect()))
def slotToolChanged(self, action):
toolFromAction = {
self.ui.actionBubble: AddBubbleTool,
self.ui.actionLine: AddLineTool,
}
klass = toolFromAction.get(action)
if klass:
tool = klass(self.scene)
else:
tool = None
self.scene.setTool(tool)
def deleteItems(self):
for shape in self.selectedShapes():
self.scene.removeShape(shape)