本文整理汇总了Python中scene.Scene.selectedItems方法的典型用法代码示例。如果您正苦于以下问题:Python Scene.selectedItems方法的具体用法?Python Scene.selectedItems怎么用?Python Scene.selectedItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scene.Scene
的用法示例。
在下文中一共展示了Scene.selectedItems方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Controller
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import selectedItems [as 别名]
class Controller(QObject):
def __init__(self, parent):
QObject.__init__(self, parent)
self.window = KMainWindow()
self.ui = Ui_MainWindow()
self.ui.setupUi(self.window)
self.createActions()
self.createDragMeWidget()
self.createScene()
self.createToolBox()
self.window.resize(700, 500)
def createScene(self):
self.scene = Scene(self.window)
self.ui.view.setScene(self.scene)
QObject.connect(self.scene, SIGNAL("selectToolRequested()"), self.slotSelectToolRequested)
QObject.connect(self.scene, SIGNAL("selectionChanged()"), self.slotSelectionChanged)
self.pixmapItem = PixmapItem()
self.pixmapItem.setZValue(-1)
self.scene.addItem(self.pixmapItem)
def createToolBox(self):
self.toolGroup = QActionGroup(self)
self.toolGroup.addAction(self.ui.actionSelect)
self.toolGroup.addAction(self.ui.actionBubble)
self.toolGroup.addAction(self.ui.actionLine)
QObject.connect(self.toolGroup, SIGNAL("triggered(QAction*)"), self.slotToolChanged)
self.ui.toolBar.addSeparator()
self.colorSelector = KColorButton()
self.colorSelector.setColor(self.scene.newShapeSettings.pen.color())
QObject.connect(self.colorSelector, SIGNAL("changed(const QColor&)"), self.slotColorChanged)
self.ui.toolBar.addWidget(self.colorSelector)
self.thicknessSelector = QSpinBox()
self.thicknessSelector.setMinimum(1)
self.thicknessSelector.setMaximum(16)
self.thicknessSelector.setValue(self.scene.newShapeSettings.pen.width())
QObject.connect(self.thicknessSelector, SIGNAL("valueChanged(int)"), self.slotThicknessChanged)
self.ui.toolBar.addWidget(self.thicknessSelector)
def createDragMeWidget(self):
dragMeWidget = DragWidget(self.tr("Drag Me"), self.window)
self.ui.mainToolBar.addWidget(dragMeWidget)
QObject.connect(dragMeWidget, SIGNAL("dragStarted()"), self.slotDragStarted)
def createActions(self):
actionOpen = KStandardAction.open(self.open, self)
actionSave = KStandardAction.save(self.save, self)
actionScreenshot = KAction(self.tr("Screenshot"), self)
actionScreenshot.setIcon(KIcon("camera-photo"))
QObject.connect(actionScreenshot, SIGNAL("triggered()"), self.grabScreenshot)
actionDelete = KAction(self)
actionDelete.setShortcut(Qt.Key_Delete)
QObject.connect(actionDelete, SIGNAL("triggered()"), self.deleteItems)
self.ui.mainToolBar.addAction(actionOpen)
self.ui.mainToolBar.addAction(actionSave)
self.ui.mainToolBar.addSeparator()
self.ui.mainToolBar.addAction(actionScreenshot)
self.window.addAction(actionDelete)
def slotDragStarted(self):
drag = QDrag(self.window)
mimeData = QMimeData()
variant = QVariant(self.imageFromScene())
mimeData.setImageData(variant)
drag.setMimeData(mimeData)
drag.start()
def selectedShapes(self):
return [self.scene.shapeForItem(x) for x in self.scene.selectedItems()]
def slotSelectToolRequested(self):
self.ui.actionSelect.setChecked(True)
self.slotToolChanged(self.ui.actionSelect)
def slotSelectionChanged(self):
shapes = self.selectedShapes()
color = None
thickness = None
if shapes:
color = shapes[0].settings.pen.color()
thickness = shapes[0].settings.pen.width()
for shape in shapes[1:]:
pen = shape.settings.pen
if color and pen.color() != color:
color = None
if thickness and pen.width() != thickness:
thickness = None
#.........这里部分代码省略.........