Navigation

    Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    1. Home
    2. Tags
    3. qgraphicsitem
    Log in to post

    • UNSOLVED Pyside6 how to disconnect connection?
      General and Desktop • qgraphicsscene qgraphicsitem signal qobje • • Dariusz  

      34
      0
      Votes
      34
      Posts
      212
      Views

      I guess I provided inadequate subtext for that example. It's documentation in a project I work on, explaining that qObject.signal.connect(lambda: anotherQObject.function(arg)) is unsafe in PyQt if anotherQObject might be destroyed before qObject. The same would happen in C++ with QObject::connect(qObject, &MyClass::signal, [&]() { anotherQObject->function(arg); }); In C++, one possible solution is to use QObject::Connect(sender, signal, context object, functor). To the best of my knowledge In PyQt5, and I suspect in PySide2/Qt for Python, there is no equivalent. You can write one by taking the connection object returned by object.signal.connect() and using it in a slot connected to anotherQObject.destroyed.
    • UNSOLVED How can my Mouse Press Event differentiate between different items?
      General and Desktop • c++ qgraphicsview qgraphicsitem qmouseevent rectangles • • MegAmaNeo1  

      8
      0
      Votes
      8
      Posts
      40
      Views

      @MegAmaNeo1 In @jsulm's outline code you need a signal named pressed in CustomItem for connect(&item, CustomItem::pressed ..., and you also need an array/QVector of bool named pressed for pressed[i]. You'll presumably need to rename one of them. And where he writes void QGraphicsItem::mousePressEvent he means your void CustomItem::mousePressEvent override.
    • UNSOLVED How to enable mouse tracking for QGraphicsItem?
      General and Desktop • qgraphicsitem • • Alex SUNPP  

      3
      0
      Votes
      3
      Posts
      49
      Views

      @SGaist yes, hovering will be okay too. I just didn't think that constant mouse tracking is such a problem.
    • UNSOLVED QGraphicsRectItem boundingRect() not updating with mousemove event
      General and Desktop • qgraphicsitem boundingrect mousemove • • sayan275  

      2
      0
      Votes
      2
      Posts
      37
      Views

      boundingRect does not depend on the position of the item with respect to the scene since it is in coordinates with respect to the item. I recommend you review https://doc.qt.io/qt-5/graphicsview.html so that you understand the different coordinate systems that are handled.
    • SOLVED How to animate a QGraphicsItem without using QGraphicsItemAnimation?
      General and Desktop • qgraphicsview qgraphicsitem animation animations • • incam  

      2
      0
      Votes
      2
      Posts
      50
      Views

      @incam https://doc.qt.io/qt-5/qpropertyanimation.html
    • UNSOLVED Painter not painting over 32,765 px in width of QGraphicsItem/QGraphicsObject
      General and Desktop • qpainter qgraphicsitem qgraphicsobject • • lansing  

      3
      0
      Votes
      3
      Posts
      47
      Views

      @mrjj Thanks, so I hit the limit. I'll try not to go over that.
    • UNSOLVED centering under mouse on QGraphicsItem when zooming
      General and Desktop • qgraphicsview qgraphicsitem center zooming • • lansing  

      1
      0
      Votes
      1
      Posts
      34
      Views

      No one has replied

    • UNSOLVED QGraphicsItem move parent instead of child...
      General and Desktop • qgraphicsitem • • Dariusz  

      2
      0
      Votes
      2
      Posts
      43
      Views

      Since QGraphicsItem::pos() Returns the position of the item in parent coordinates. So the item and its parent item are not in the same coordinate system. I think you should calculate the offset between pos() and value, then calculate the new pos of mParentItem by adding offset to mParentItem->pos().
    • UNSOLVED Connect 2 custom movable QGraphicsItems with an auto adjustable multiline
      General and Desktop • qgraphicsscene qgraphicsitem • • ppetukhov  

      1
      0
      Votes
      1
      Posts
      44
      Views

      No one has replied

    • UNSOLVED QGraphicsProxyWidget undo ItemStacksBehindParent?
      General and Desktop • qt5 pyside2 qgraphicsitem pyqt5 qgraphicsproxyw • • Goffer  

      1
      0
      Votes
      1
      Posts
      54
      Views

      No one has replied

    • UNSOLVED QGraphicsItemGroup in a QGraphicsLayout
      General and Desktop • qgraphicsitem qgraphicsitemgr qgraphicslayout • • Clement135  

      7
      0
      Votes
      7
      Posts
      131
      Views

      @SGaist I have tried many things so there are a few comments Here the minimal code below: main.cpp: #include "QApplication" #include "graphicsitemgroup.h" #include "qgraphicslinearlayout.h" #include "qgraphicsscene.h" #include "qgraphicsview.h" #include "graphicswidget.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); auto widget = new QGraphicsWidget(nullptr, Qt::Window); auto item_0 = new GraphicsItemGroup(widget); auto item_1 = new GraphicsItemGroup(widget); auto linearLayout = new QGraphicsLinearLayout(); linearLayout->addItem(item_0); linearLayout->addItem(item_1); widget->setLayout(linearLayout); QGraphicsScene scene; scene.addItem(widget); QGraphicsView view(&scene); view.setResizeAnchor(QGraphicsView::AnchorViewCenter); view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view.show(); return app.exec(); } graphicsitemgroup.h: #ifndef GRAPHICSITEMGROUP_H #define GRAPHICSITEMGROUP_H #include "qgraphicslayoutitem.h" #include "QGraphicsItemGroup" #include "qsize.h" class GraphicsItem; /** * @brief Placeholder for graphics items */ class GraphicsItemGroup : public QGraphicsLayoutItem, public QGraphicsItemGroup { public: GraphicsItemGroup(QGraphicsItem* parent = nullptr); virtual ~GraphicsItemGroup(); void setGeometry(const QRectF& geometry) override; QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint = QSizeF()) const override; // QRectF boundingRect() const override; void paint(QPainter *painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; private: QSizeF m_size; GraphicsItem* m_item; }; #endif // GRAPHICSITEMGROUP_H graphicsitemgroup.cpp: #include "graphicsitemgroup.h" #include "graphicsitem.h" #include "qpainter.h" #include "qdebug.h" GraphicsItemGroup::GraphicsItemGroup(QGraphicsItem* parent) : QGraphicsItemGroup(parent) , m_size(QSize(100, 100)) , m_item(new GraphicsItem(QSizeF(50, 50))) { addToGroup(m_item); setGraphicsItem(this); } GraphicsItemGroup::~GraphicsItemGroup() = default; void GraphicsItemGroup::setGeometry(const QRectF& geometry) { prepareGeometryChange(); QGraphicsLayoutItem::setGeometry(geometry); setPos(geometry.topLeft()); qDebug() << __PRETTY_FUNCTION__; } QSizeF GraphicsItemGroup::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const { switch (which) { case Qt::MinimumSize: case Qt::PreferredSize: return m_size; case Qt::MaximumSize: default: break; } return constraint; } //QRectF GraphicsItemGroup::boundingRect() const //{ // return QRectF(QPointF(0, 0), geometry().size()); //} void GraphicsItemGroup::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { painter->drawRect(QRectF(QPointF(0, 0), geometry().size())); } graphicsitem.h: #ifndef GRAPHICSITEM_H #define GRAPHICSITEM_H #include "qgraphicslayoutitem.h" #include "qgraphicsitem.h" #include "qsize.h" class QRectF; class QPainter; class QStyleOptionGraphicsItem; class GraphicsItem : /*public QGraphicsLayoutItem,*/ public QGraphicsItem { public: GraphicsItem(QSizeF size, QGraphicsItem* parent = nullptr); virtual ~GraphicsItem(); // void setGeometry(const QRectF& geometry) override; // QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint = QSizeF()) const override; QRectF boundingRect() const override; void paint(QPainter *painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; private: QSizeF m_size; }; #endif graphicsitem.cpp: #include "graphicsitem.h" #include "qpainter.h" #include "qrect.h" #include "qdebug.h" GraphicsItem::GraphicsItem(QSizeF size, QGraphicsItem* parent) : QGraphicsItem(parent) , m_size(size) { // setGraphicsItem(this); } GraphicsItem::~GraphicsItem() = default; //void GraphicsItem::setGeometry(const QRectF& geometry) //{ // prepareGeometryChange(); // QGraphicsLayoutItem::setGeometry(geometry); // setPos(geometry.topLeft()); // // qDebug() << __PRETTY_FUNCTION__; //} // //QSizeF GraphicsItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const //{ // switch (which) // { // case Qt::MinimumSize: // case Qt::PreferredSize: // return m_size; // case Qt::MaximumSize: // default: // break; // } // // return constraint; //} QRectF GraphicsItem::boundingRect() const { return QRectF(QPointF(20, 20), m_size); } void GraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { painter->drawRect(boundingRect()); } CMakeLists.txt: cmake_minimum_required(VERSION 3.0) project(GraphicsLayoutExample) find_package(Qt5 COMPONENTS Core REQUIRED Widgets REQUIRED Gui REQUIRED ) add_executable(${CMAKE_PROJECT_NAME} main.cpp graphicsitemgroup.cpp graphicsitem.cpp ) target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC .) target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Qt5::Widgets Qt5::Core Qt5::Gui) I would like to have the graphics item (here a little rectangle) to be resized depending on the a graphics item group (the latter paints another rectangle just to have a visual on what is going on). In the future, I have planned to put two graphics items (one over the other) in the group. Thanks for your help.
    • SOLVED Creating a QGraphicsItem in the position of the context menu not positioning properly
      General and Desktop • qgraphicsscene qgraphicsitem • • amansahil  

      6
      0
      Votes
      6
      Posts
      146
      Views

      @amansahil Check after setting the position if polygon->scenePos() - clickPoint == (0, 0). If it is, there's a problem with the event->scenePos(), and if not, there's a problem with how the polygon position is being set. The right conversion would be polygon->setPos( clickPoint - polygonParent->scenePos() ) mapFromScene() is better than mapToScene() since you have the coordinates in the scene frame and you want them in local coordinates. But it still isn't quite right! You specify position in the local parent coordinates, not the local item frame. So that approach to use is polygon->setPos( polygonParent->mapFromScene(clickPoint) )
    • UNSOLVED QGraphicsItem ignores mouse release event when ItemIsMovable is false.
      General and Desktop • qgraphicsview qgraphicsscene qgraphicsitem mouseevent flag • • Forfunckle  

      5
      0
      Votes
      5
      Posts
      76
      Views

      @mrjj Yes, it worked. Thank you!
    • UNSOLVED Resize a rotated GraphicsItem from Center
      General and Desktop • qgraphicsscene qgraphicsitem • • sayan275  

      1
      0
      Votes
      1
      Posts
      57
      Views

      No one has replied

    • UNSOLVED Clipping QGraphicsItems in a QChart
      General and Desktop • qgraphicsitem qchart clipping • • wombatonfire  

      3
      0
      Votes
      3
      Posts
      97
      Views

      For sure it can be measured, and I do agree with the approach "if it works fine, just use it". But I am still curious, why clipping is expensive in the first place, so that the warning exists in the docs? Has anyone experienced performance impact while actively using clipping for real-time chart?
    • UNSOLVED QGraphicsView - custom curve dissapearing when too close
      General and Desktop • qgraphicsview qgraphicsscene qgraphicsitem • • Dariusz  

      3
      0
      Votes
      3
      Posts
      120
      Views

      It appears that QGraphicsScene checks if position of item is visible in view and then draws/dont draws it... returning qgraphicsScene->sceneRect() as boundingRect on my curve "solved" the issues but its a problem for selectable items... hmmm
    • UNSOLVED Custom QGraphicsView items are not movable
      General and Desktop • qgraphicsview qgraphicsitem qgraphicsellips • • hobbyProgrammer  

      2
      0
      Votes
      2
      Posts
      116
      Views

      Hi I think you just broke GraphicsView normal handling. Try also calling base class mousePressEvent as it might use for the actual item selection void GraphicsView::mousePressEvent(QMouseEvent *event) { if(event->buttons().testFlag(Qt::LeftButton)) { int x,y; x = event->pos().x(); y = event->pos().y(); qDebug() << x << ", " << y; QPointF point = mapToScene(x, y); QGraphicsEllipseItem *ellipse; ellipse = scene->addEllipse(point.x(),point.y(),5,5,QPen(Qt::red), QBrush(Qt::red)); ellipse->setFlag(QGraphicsEllipseItem::ItemIsMovable); } // call base class QGraphicsView::mousePressEvent(event); }
    • UNSOLVED Arial italic font dont work right on qgraphicsscene
      General and Desktop • qgraphicsscene qgraphicsitem paint fonts • • mehmetkarlik  

      2
      0
      Votes
      2
      Posts
      92
      Views

      Hi, Can you provide a minimal compilable code that shows that behaviour ?
    • UNSOLVED QGraphicsItem - itemChanged & child items issue
      General and Desktop • qgraphicsitem • • Dariusz  

      1
      0
      Votes
      1
      Posts
      82
      Views

      No one has replied

    • UNSOLVED QGraphicsItem, location of 2 items in each other local space
      General and Desktop • qgraphicsitem • • Dariusz  

      5
      0
      Votes
      5
      Posts
      170
      Views

      @SGaist Possibly yes... I'm back to this & lost again... I think I figured out the last problem without needing it, but now I need it again... Scenario = bezier curve, 4 points, first start, control left, control right, endpoints. Start and end can never cross each other on Z-axis. Control left can not pass end on the Z-axis and control Right can not pass start on z-axis either. Control points are children of start/endpoints. (Hope this make sense...) So what I need to find out is... location of End point while being inside Control Left event. I need to somehow map scenePos() of End point to my Control Left local space.... here is some debuging I was trying to do... (test case, moving right control point towards left Start item) targetPos : QPointF(348,-478) // scenePos() of Start item myPos : QPointF(336,-617) // scenePos() of rightControl scenePos() - already invalid position because we passed the Z location of targetPos item. myLocPos : QPointF(-237,2) This should match other item loc at some point... localPos of rightControl mapFromScene: QPointF(12,139) // mappings mapToItem : QPointF(113,-477) // mappings mapFromItem : QPointF(583,-479) // mappings one of mappings should return a number close to myLocPos but none of them do :- ( Debug code : qDebug() << "oh snap!" << "\n targetPos : " << itemPos << "\n myPos : " << myPos << "\n myLocPos : " << newPos << "local pos of rightControl item" << "\n mapFromScene: " << mapFromScene(itemPos) << "\n mapToItem : " << mapToItem(items[x], itemPos) << "\n mapFromItem : " << mapFromItem(items[x], itemPos); Esentially this : Top left item, is the myPos/newPos variable newPos being local and myPos being scenePos(), item below is the "Start"
    • UNSOLVED QGraphicsView - dragMove items - signal/slot ?
      General and Desktop • qgraphicsview qgraphicsitem • • Dariusz  

      2
      0
      Votes
      2
      Posts
      127
      Views

      Hi, Without more details form you side, it looks like that's the function you are looking for.
    • SOLVED Scale items position relative to the scene/view resizing
      General and Desktop • qt5 qgraphicsview qgraphicsscene qgraphicsitem • • alizadeh91  

      3
      0
      Votes
      3
      Posts
      507
      Views

      Call fitInView on the GraphicsView with the Image whenever the size of the GraphicsView changes. The rest should work automatically.
    • SOLVED Crop pixmap from qgraphicsscene with qgraphicsItem
      General and Desktop • qgraphicsscene qgraphicsitem qpixmap • • sayan275  

      6
      0
      Votes
      6
      Posts
      820
      Views

      Hi, I got the expected output from grab(QRect) https://stackoverflow.com/questions/16362191/qt-grab-widget-and-save-image m_graphicsView->grab(rect).save("OUT.jpg"); Thanks all.
    • UNSOLVED Application crashes while accessing Pointers and while Hovering over custom QGraphicsItems
      General and Desktop • c++ qgraphicsitem segfault pointer • • Lanparty  

      14
      0
      Votes
      14
      Posts
      1050
      Views

      @Lanparty said in Application crashes while accessing Pointers and while Hovering over custom QGraphicsItems: btw: how do I change the status of my post to "solved"? First post, Topic Tools button to the side.
    • SOLVED QGraphicsItem select only border
      General and Desktop • qgraphicsview qgraphicsscene qgraphicsitem • • Gianluca86 0  

      4
      0
      Votes
      4
      Posts
      475
      Views

      Thanks @SGaist and @raven-worx , I try both methods to see which one to use better in my program.
    • UNSOLVED add a QToolbar as a child of a QGraphicsItem
      General and Desktop • qgraphicsitem qtoolbar mousepressevent maptoscene • • sayan275  

      2
      0
      Votes
      2
      Posts
      283
      Views

      Hi, What about QGraphicsProxyWidget ?
    • SOLVED Make QGraphicsItem cover items under it
      General and Desktop • qgraphicsscene qgraphicsitem background graphicsview • • mbise1993  

      6
      0
      Votes
      6
      Posts
      382
      Views

      I found the problem. I was drawing the beats before the lines, so the lines took precedent over the beats since they are siblings. The solution was to either draw the beats last or set the Z value on the beat, not the note.
    • SOLVED (Pure) Abstract class that inherits from QGraphicsItem
      General and Desktop • qgraphicsitem inheritance custom item abstract class • • Pl45m4  

      2
      0
      Votes
      2
      Posts
      471
      Views

      Hi As long as you dont do multiple inheritance , i think you base class design should work just fine. However, make sure to overrride int QGraphicsItem::type() const pr concrete class to make sure qgraphicsitem_cast() works.
    • SOLVED Creating a pedigree chart
      General and Desktop • qgraphicsview qgraphicsscene qgraphicsitem • • ByronCoughlin  

      7
      0
      Votes
      7
      Posts
      773
      Views

      @mrjj There are other obstacles that I need to overcome. But this way seems to be the solution that i am implementing. Thanks
    • UNSOLVED Manual resizing of QGraphicsItem using mouse
      General and Desktop • qgraphicsview qgraphicsscene qgraphicsitem resize mouse event • • hellozee  

      1
      0
      Votes
      1
      Posts
      555
      Views

      No one has replied

    • UNSOLVED QGraphicsRectItem coordinate system on image resize
      General and Desktop • qgraphicsscene qgraphicsitem resize mapto • • sayan275  

      3
      0
      Votes
      3
      Posts
      615
      Views

      @raven-worx I tried the following but didn't work out.. QGraphicsPixmapItem* item = new QGraphicsPixmapItem(QPixmap::fromImage(qImage, Qt::AutoColor)); m_ViewerScene->addItem(item); QGraphicsRectItem* rect = new QGraphicsRectItem(m_BoundingBox); m_ViewerScene->addItem(rect); rect->setParentItem(item); m_ViewerScene->update(); //add the resized QGraphicsPixmapItem to the pixmap item->setPixmap( item->pixmap().scaled(QSize(128, 32),Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); qInfo()<<"Rect resize props:::"<<item->childItems()[0]->boundingRect(); m_BoundingBox = item->childItems()[0]->boundingRect(); later I'm drawing box, on the image in an other viewer, with m_BoundingBox. The grey area within the blue rectangle will be resized to 128 * 32, and then the red rectangle would be added on the resized image. How to get the co-ordinates of red rect on the resized image?
    • SOLVED QGraphicsItem parent child event handling
      General and Desktop • qgraphicsitem • • Glenn94  

      3
      0
      Votes
      3
      Posts
      1118
      Views

      @Asperamanca Thanks for the reply, I fixed it by seperating the problem instead of making one compound Qgraphicsitem, which was the goal.
    • UNSOLVED How to create a menu using GraphicsScene with buttons
      Mobile and Embedded • qgraphicsscene qgraphicsitem menu • • mounipanditi  

      1
      0
      Votes
      1
      Posts
      443
      Views

      No one has replied

    • UNSOLVED How to create few transparent, z-order independent QGraphicsItem?
      General and Desktop • qgraphicsitem transparency scene opacity z-order • • flart  

      3
      0
      Votes
      3
      Posts
      2283
      Views

      @kenchan I knew that. I want not stacking by z-order, I want simultaneous stacking. It works something like that by default (if opacity of items is 0.5 ) output = Merge(Merge(background, 0.5 × item1), 0.5 × item2) I want something like that output = Merge(background, 0.5 × item1, 0.5 × item2) aka simultaneous merge items to scene, so it not depends from z-order. (example — I want ⅓ background, ⅓ item1 and ⅓ item2, Indifferently to items z-order)
    • UNSOLVED Deleting QGraphicsItem with QGraphicsEffect leads to segfault
      General and Desktop • qgraphicsitem qgraphicseffect c++ qt qgraphic • • tfm123  

      21
      0
      Votes
      21
      Posts
      6187
      Views

      @tfm123 I think this bug is described here: https://bugreports.qt.io/browse/QTBUG-18021 My workaround was to setVisible(false) before removing the item.
    • SOLVED QGraphicsItem gets selected when clicking outside of visible shape
      General and Desktop • qgraphicsview qgraphicsscene qgraphicsitem qt4 zoom • • Vaniax  

      9
      0
      Votes
      9
      Posts
      4527
      Views

      :D I haven't had much time to test if the bug exists in Qt5. I'll check it out and update the topic accordingly. If the bug is still there, of course, I will submit the fix. Thanks for your time.
    • Rotating a QLabel
      General and Desktop • qwidget qgraphicsitem qimage scale rotation • • sunil.nair  

      3
      0
      Votes
      3
      Posts
      2974
      Views

      You can add a widget to the scene using QGraphicsProxyWidget *QGraphicsScene::addWidget(QWidget *widget, Qt::WindowFlags wFlags = Qt::WindowFlags()).
    • QGraphicsItem Border
      General and Desktop • qgraphicsview stylesheet qgraphicsitem qimage • • sunil.nair  

      3
      0
      Votes
      3
      Posts
      1924
      Views

      Hi, you should be able to do so by overriding the QRectF boundingRect() const function. Just call the base function to get the current rect., and return rect.adjusted(2,2,2,2). -Michael.