qgraphicsitem

PySide/PyQT5: How to emit signals from a QGraphicsItem?

妖精的绣舞 提交于 2020-01-15 09:20:28
问题 I want to emit a signal from a QGraphicsItem when it is doubled-clicked, in order to change a widget in the main window. The graphics-scene/-item does not provide an emit() method, but I was just wondering if there is an alternate way to do this. The code below has a function within a QGraphicsView class that will print to the terminal when an item is double-clicked. How can I make that into a slot/signal instead (if QGraphicsItem does not support signal/slots)? import sys from PySide.QtCore

Why are my custom graphical items constantly repainting in a Qt-based C++ GUI application?

别说谁变了你拦得住时间么 提交于 2020-01-15 03:26:09
问题 My application has a QMdiArea, inside which subwindows are shown which contain instances of QGraphicsView-derived views (GfxInteractiveView), which in turn visualize scenes containing custom QGraphicsItem-derived items. /// An image item which is displayed as the background of a scene. class GfxImageItem : public QObject, public QGraphicsPixmapItem { Q_OBJECT protected: GfxInteractiveImgView *view_; QPixmap pixmap_; QList<GfxPointItem *> pointItems_; public: GfxImageItem(GfxInteractiveImgView

Alternatives to static and global in C++?

 ̄綄美尐妖づ 提交于 2020-01-14 07:11:11
问题 I have a class instance that needs to be accessed by some other classes. It would be quite cumbersome to pass the instance always down the construction chain. I tried to avoid global variable, since people tend to advise against this. I thought I declare this instance a static member of a class and then include this class in order to access the instance but this does not work either error: calling a private constructor of class 'Foo' To specify the problem further in the context of the

Resizing and rotating a QGraphicsItem results in odd shape

蓝咒 提交于 2020-01-13 10:06:20
问题 I can't understand how scaling and rotation are applied to QGraphicsItem . I need to be able to apply rotation and scaling ( not necessarily keeping aspect ratio ) and I get fully unexpected results. Rotation must be around the item center. I seem to have no problem doing that - yet if I try to debug the bounding rectangle, I get seemingly wrong values. If I don't keep aspect ratio, instead of rotation I get a very weird skew, and I have been struggling for quite a while to find the cause and

Resizing and rotating a QGraphicsItem results in odd shape

谁说我不能喝 提交于 2020-01-13 10:05:33
问题 I can't understand how scaling and rotation are applied to QGraphicsItem . I need to be able to apply rotation and scaling ( not necessarily keeping aspect ratio ) and I get fully unexpected results. Rotation must be around the item center. I seem to have no problem doing that - yet if I try to debug the bounding rectangle, I get seemingly wrong values. If I don't keep aspect ratio, instead of rotation I get a very weird skew, and I have been struggling for quite a while to find the cause and

QGraphicsPathItem hoverEvents - suppress hover on area formed by the path

一世执手 提交于 2020-01-06 03:17:51
问题 https://www.dropbox.com/s/phven3rriv36893/graphicsview-pathitem.png?dl=0 I wonder if there's a way to make my QGraphicsPathItem respond to mouseHoverEvents to the actual curve instead of the whole orange area as seen in the docs. https://www.dropbox.com/s/7m8w34nitp34sgf/pipes.png?dl=0 In my application I'm not seeing the area that actually forms the path and therefor I only want a hoverEnterEvent when the bezier curve is hovered (and a hoverLeaveEvent when the bezier is left of, course). Is

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call

与世无争的帅哥 提交于 2020-01-01 09:17:37
问题 I created a simple program that demonstrates the runtime error I'm getting with my Qt application that uses multiple inheritance. The inheritance tree looks like: QGraphicsItem (abstract) \ QGraphicsLineItem MyInterface (abstract) \ / \ / MySubclass And here is the code: /* main.cpp */ #include <QApplication> #include <QGraphicsScene> #include <QGraphicsLineItem> //simple interface with one pure virtual method class MyInterface { public: virtual void myVirtualMethod() = 0; }; //Multiple

Prevent QGraphicsItem from moving outside of QGraphicsScene

为君一笑 提交于 2020-01-01 08:33:55
问题 I have a scene which has fixed dimensions from (0;0) to (481;270): scene->setSceneRect(0, 0, 481, 270); Inside of it, I have a custom GraphicsItem and I can move it thanks to the flag ItemisMovable , but I would like it to stay within the Scene; I actually mean I don't want it to have coordinates neither under (0;0) nor over (481;270). I tried several solutions like overriding QGraphicsItem::itemChange() or even QGraphicsItem::mouseMoveEvent() but I still cannot manage to reach what I want to

QGraphicsSimpleTextItem “invalid use of incomplete type”

寵の児 提交于 2019-12-31 07:16:05
问题 My code is as follows: pointerwidget.h QGraphicsSimpleTextItem *text; pointerwidget.cpp void PointerWidget::placeNumbers(float spacing, int currentTickNumber) { float label = spacing/scaleFactor; text = scene->addSimpleText(QString::number(label),QFont("Comic Sans MS", 12, QFont::Bold)); text->setPos(currentTickNumber*spacing,30); } Everywhere that i read says to use setPos(x,y) to position the text item. This is a function of QGraphicsItem. I get the error of "invalid use of incomplete type

Scaling a rotated item based on top left moves the item

自闭症网瘾萝莉.ら 提交于 2019-12-24 16:43:10
问题 I would like to be able to rotate a QGraphicsItem based on its center, and scale it based on the top left corner. When I try to combine rotation and scaling, the item also apparently moves... #include <QApplication> #include <QGraphicsView> #include <QGraphicsTextItem> void testTransformations(QGraphicsScene* s) { qreal angle = 30, scaleX = 2, scaleY = 1; // Reference rotated not scaled QGraphicsTextItem* ref = new QGraphicsTextItem("bye world"); ref->setFont(QFont("Arial", 20)); ref-