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

Why the paintevent is not working?



  • Hi, I've created two QDialogs and connect them together by using signal and slot in the main.cpp. What I wish to see is that when I draw a line on the first window, it will be displayed on the second one. I am certain that the signal is accepted by the slot as printPath() is able to print out the path. However, the second window is not updated when I call the update() in setPath(). Why is that?

    void Receiver::paintevent(QPaintEvent *e)
    {
        QPainter painter(this);
        painter.drawPath(*path);
    }
    void Receiver::setPath(QPainterPath* inPath)
    {
        path = inPath;
        update();
        printPath();
    }
    

  • Moderators

    It should be paintEvent, not paintevent. When overriding virtual members use the override keyword in the header. It will help you catch typos like this.

    Also, since you're passing the path through a pointer, make sure that path object is still alive when paintEvent is called, otherwise that's undefined behavior.


  • Moderators

    It should be paintEvent, not paintevent. When overriding virtual members use the override keyword in the header. It will help you catch typos like this.

    Also, since you're passing the path through a pointer, make sure that path object is still alive when paintEvent is called, otherwise that's undefined behavior.


Log in to reply