Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Solved] Dragging a QGraphicsItem over another is distorting the other QGraphicsItem's color



  • Hi.
    I have implemented a QGraphicsRectItem inside a QGraphicsPolygonItem. The QGraphicsRectItem item displays a color.
    When i slide one QGraphicsPolygonItem over the other, the color is getting distorted and becoming white(default color of it's parent i.e. QGraphicsPolygonItem)

    I have implemented following -
    @
    void DiagramItem::paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget )
    {
    ……

    if (option->state & QStyle::State_Selected)
    {
    

    …..
    scene()->update();
    }
    }
    @

    where DiagramItem is a subclass of QGraphicsPolygonItem.
    This tremendously increases my CPU utilization....

    What is a probable solution to this problem ?

    Thanks.



  • I don't really see how your code snippet relates to your problem. Maybe you could post a more complete code sample?

    I find it interesting that you call scene()->update(); within paint - couldn't that cause the CPU utilization?



  • I recognized my error. I created a public function which mocks functionality of paint() in QGraphicsRectItem and then call the dummy paint() from QGraphicsPolygonItem.


Log in to reply