qgraphicsitem

Hide area of QGraphicsItem that is out of boundary

纵然是瞬间 提交于 2021-02-10 18:16:11
问题 I have a QGraphicsPixmap item in a QGraphicsScene . The item has flags set to ItemIsMovable , and ItemIsSelectable . How do I ensure that when the item is moved out of a certain boundary - it can be a QGraphicsScene or just a fixed frame size at fixed coordinates - the part becomes hidden? Eg. The left part of the basketball becomes hidden. 回答1: You have to use setClipPath() . In the following code I have created a class that inherits from QGraphicsPixmapItem (the same could do with other

PyQt: QGraphicsItem added at a wrong position

老子叫甜甜 提交于 2021-01-28 19:09:38
问题 I have a subclass of QGraphicsItem and I want to add instances of it to the scene on 'Control+LMB click'. The trouble is that the item is added at the position with coordinates that are two times larger than they should be. At the same time adding ellipses with scene.addEllipse(...) works fine. #!/usr/bin/env python import sys from PyQt4.QtCore import (QPointF, QRectF, Qt, ) from PyQt4.QtGui import (QApplication, QMainWindow, QGraphicsItem, QGraphicsScene, QGraphicsView, QPen, QStyle) MapSize

Qt: qgraphicsitem drag and drop

给你一囗甜甜゛ 提交于 2021-01-28 04:46:37
问题 I have a problem with Qt. I want to drag an image and use of QGraphicsPixmapItem and dragenterevent but it doesnt appear in the console ? but other function like hoverEnterEvent work corectly??? here is the code: please help? class button : public QGraphicsPixmapItem { public: button(const QPixmap &); button(); void changepic( QPixmap,int ,int); void mousePressEvent(QGraphicsSceneMouseEvent*event); void dragenterEvent(QGraphicsSceneDragDropEvent *event){ event->setAccepted(1); qDebug("drag");

How to anchor QGraphicsWidget/Item (make them static) on QGraphicsView

扶醉桌前 提交于 2020-02-25 04:36:20
问题 I want to make something like a hud. I have a QGraphicsScene with a huge QPixmap , that I added to a much smaller QGraphicsView . Now I need to add some control elements, like QLabel , QPushButton and QGraphicsEllipseItem . That's, I think, is not a problem. I found this helpful page Graphics View Classes. But how do I anchor this control elements to the View or maybe better said how do I not anchor them? When I drag the QPixmap , then I don't want that the hud is moving with the QPixmap out

PyQt4: QGraphicsItem mousePressEvent() disables flag ItemIsMovable

試著忘記壹切 提交于 2020-02-05 13:38:52
问题 Here's a bug which I accidently solved it and have no idea why that works. I hope that someone could explain to me the logics behind it. I've reimplmented QGraphicsItem and its mousePressEvent. By doing that the item was no longer movable. Even when trying to call QGraphicsItem.mousePressEvent(self, event) it didn't work. Only when I reimplmented mouseMoveEvent() and mouseReleaseEvent() it finally worked. Code: class LWResizeableItem(QtGui.QGraphicsItem): def __init__(self): super

Only move QGraphicsItem when mouse in specific region

雨燕双飞 提交于 2020-02-02 11:11:46
问题 I'm trying to create something similar to terragens node network view in python using PySide. I subclassed QGraphicsRectItem using this code. class Node(QGraphicsRectItem): def __init__(self,pos): QGraphicsRectItem.__init__(self,pos.x()-100,pos.y()-30,200,60) self.setFlag(QGraphicsItem.ItemIsMovable,True) (...) Which gives this (with some fancy painting): I'd like to implent connecting nodes by dragging the mouse from one small rectangle to another, but this results in moving the whole node.

How can I hide the caret when not in edit mode?

拜拜、爱过 提交于 2020-01-24 20:51:26
问题 I have a TextItem inheriting QGraphicsTextItem . I made it so that on double-click I can edit the text, and when clicking out, the text is no longer editable. void TextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event) { setTextInteractionFlags(Qt::TextEditorInteraction); setFocus(); int p = document()->documentLayout()->hitTest(event->pos(), Qt::FuzzyHit); QTextCursor _cursor = textCursor(); _cursor.setPosition(p); setTextCursor(_cursor); } void TextItem::focusOutEvent(QFocusEvent

drawing plot lines on QGraphicsScene

 ̄綄美尐妖づ 提交于 2020-01-16 07:30:30
问题 I designed a QGraphicsScene like a graph with scale at both axis and with the data i able to plot points on the the scene using QGraphicsItem. but I don’t know which method will be suitable for connecting the points so it can be look like a graph plotted. PainterPath or some other specific things ? 回答1: I'd say QPainter::drawPolyline() is a good option (or QPainterPath::addPolygon). You can use QPolygonF to contain your points. Then you just pass this to the QPainter's drawPolyline function.

QGraphicsItem interactive resizing

こ雲淡風輕ζ 提交于 2020-01-16 00:46:38
问题 i've forked the project https://github.com/cesarbs/sizegripitem that is a intercative QGraphicsItem resizing with 8 handlers, the problem is that if i set my main QGraphicsItem to be Selectable, when i drag the handlers, the main QGraphicsItem moves rather then being resized, bellow is the source for SizeGripItem.cpp /* * SizeGripItem - A size grip QGraphicsItem for interactive resizing. * * Copyright (c) 2011 Cesar L. B. Silveira * * Permission is hereby granted, free of charge, to any