qgraphicsitem

QGraphicsLineItem::paint() artifacts

不羁的心 提交于 2019-12-11 04:09:09
问题 I have my own class which inherits from QGraphicsLineItem and overrides the paint() method to draw a thick line with an arrow head: void MyGraphicsItem::paint( QPainter* aPainter, const QStyleOptionGraphicsItem* aOption, QWidget* aWidget /*= nullptr*/ ) { Q_UNUSED( aOption ); Q_UNUSED( aWidget ); QLineF cLine = line(); aPainter->setPen( QPen( Qt::black, 6, Qt::SolidLine ) ); aPainter->drawLine( cLine ); qreal lineAngle = cLine.angle(); const qreal radius = 2.0; QLineF head1 = cLine; head1

QGraphicsPixmapItem not selectable

試著忘記壹切 提交于 2019-12-11 02:21:35
问题 I want my QGraphicsPixmapItem become selectable (i.e. clickable in more general way) on QGraphicScene but it doesn't. I'm actually modifying Qt 's Diagram Scene sample, where QGraphicsItem 's subclass is used and is selectable. I appreciate your help. cpp code (partial): #include <iostream> #include <QtGui> #include "overlayPixmapItem.h" OverlayPixmapItem::OverlayPixmapItem(DiagramType diagramType, QMenu *contextMenu, QPixmap img, QGraphicsItem *parent, QGraphicsScene *scene) :

PyQt/PySide How to access/move QGraphicsItem after having added it to QGraphicsScene

天大地大妈咪最大 提交于 2019-12-11 01:42:19
问题 This might be a very uninformed question. I've been trying to figure out QGraphics* , and have run into a problem when trying to move an item (a pixmap) relative to or inside of the QGraphicsView . class MainWindow(QMainWindow,myProgram.Ui_MainWindow): def __init__(self): super().__init__() self.setupUi(self) self.scene = QGraphicsScene() self.graphicsView.setScene(self.scene) pic = QPixmap('myPic.png') self.scene.addPixmap(pic) print(self.scene.items()) This is the relevant part of the

Qt: restrict movable area of a QGraphicsItem inside an other QGraphicsItem C++

杀马特。学长 韩版系。学妹 提交于 2019-12-11 01:23:09
问题 I think my question is similar to this post but in C++ and inside a QGraphicsItem. I would like to fix the movable area of my object inside an other QGraphicsItem. I want my object to stay inside if I try to move it outside. Maybe the idea will be to use setParentItem() . Does someone know how to restrict a movable area inside a QGraphicsItem please? 回答1: Yes, you are correct. As in here you have to reimplement itemChange. From the qt documentation QVariant Component::itemChange

itemChanged() in QGraphicsItem for a many different items

三世轮回 提交于 2019-12-10 19:49:20
问题 I have an application containing many different items in a QGraphisScene . These items would be rectangles, ellipses, pixmaps, or anything that inherits from QGraphicsItem . The user can move around these items. (each of the QGraphicsItem::ItemIsMovable flag is set). The application needs to get an event (a callback, a signal or whatever) to get the new position. How can I overload the itemChanged() method for all of these possible items in one go?. I'd like do avoid subclassing each of my

Child items not movable in QGraphicsView when ItemIsMovable flag is set

三世轮回 提交于 2019-12-10 18:18:18
问题 To resize items in a QGraphicsView, I'm putting child items representing vertices onto the item to be moved (using the parent-child relationship established in the constructor). Those are the four blue circles in the picture below: But the child vertices are not receiving mouse events. Only the parent item (red square) is getting mouse events. Here is the definition for Item : Item::Item(QGraphicsItem * parent) : QGraphicsItem(parent) { setFlag(ItemIsMovable); setFlag(ItemIsSelectable);

In ScrollHandDrag mode of QGraphicsView, How to stop movement of QGraphicsItems on scene?

无人久伴 提交于 2019-12-10 12:58:53
问题 I have multiple QGraphicsItem s in scene spread across different parts of scene. In application there are different modes in one of mode user can scroll the scene (palm drag mode). To achieve scrolling over scene I set dragMode of QGraphicsView to ScrollHandDrag . But the problem is when user try to scroll over scene by dragging ( MousePress and MouseMove ) on any of QGraphicsItem instead of scrolling scene it moves QGraphicsItem . How can I stop movement of QGraphicsItem and scroll the scene

How to rotate selected QGraphicsItems around the selection center?

半世苍凉 提交于 2019-12-10 11:35:03
问题 I would like to implement rotation of selected items. I have noticed that there are 2 functions - rotate() which performs an immediate action but does not save the rotation on the item - and setRotation(), which stores rotation() (though it requires a repaint causing event). If I select a single item and rotate it, I can set selectedItem->setRotation(selectedItem->rotation() + deg); This allows the item to store its rotation, and when I need to copy it to another scene, the item retains its

Qt update() doesn't work

为君一笑 提交于 2019-12-07 16:48:16
问题 I have a problem , that update() function in QGraphicsItem doesn't work. What I want to do is , when I move circle , other QGraphicsItem ( in the mean time roundrect ) changes color. This is a example, what I want to do: circle.cpp: void CircleItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { // RoundRect Object RectItem->SetBackGround(); QGraphicsItem::mouseMoveEvent( event ); } RoundRect.cpp: void RoundRectItem::SetBackGround() { ChangeBackground = true; update(); } void RoundRectItem

Subclassing QGraphicsView and setting drawBackground

故事扮演 提交于 2019-12-07 09:57:29
问题 I'm trying to make a function similar to impoly (from matlab) in Qt. Right now, I have a subclass of QGraphicsView and have set the virtual function "drawBackground" as: void roiwindow::drawBackground(QPainter *painter, const QRectF &rect) { painter->save(); painter->drawImage(rect, *refimage); painter->restore(); } This works great and is basically exactly what I want as far as the background layer. Now, I'm trying to add circles that will eventually act as nodes for the polygon. I did this