Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWidget::paintEngine: Should no longer be called

QWidget::paintEngine: Should no longer be called

Scheduled Pinned Locked Moved Solved General and Desktop
qgraphicsviewpainteeventqpainter
10 Posts 5 Posters 9.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Staslend
    wrote on last edited by
    #1

    I saw topics of people who has the same error. I understand that all using of QPainter must happened in the paintEvent. I done this, but problem still exist.
    This is the code of function:

    void GraphicsView::painEvent(QPaintEvent *event)
    {
        QPainter  painter(viewport());
    
        painter.setPen(Qt::blue);
        painter.setFont(QFont("Arial", 30));
        painter.drawText(rect(), Qt::AlignCenter, "Qt");
    }
    

    In short, I create class that inherited from QGraphicsView. I rewrite some functions, but I do not think that problem in them. There is a full code of my program:

    GraphicsView.h

    #include <QGraphicsView>
    #include <QEvent>
    #include <QPainter>
    #include <QPaintEvent>
    
    class GraphicsView : public QGraphicsView
    {
        Q_OBJECT
    
        using  QObject :: event;
        using  QGraphicsView :: paintEvent;
    
    public:
        GraphicsView();
        virtual ~GraphicsView();
    
    
        bool eventFilter(QObject *object, QEvent *event);
        virtual void painEvent(QPaintEvent * event);
    };
    
    

    GraphicsView.cpp

    #include "graphicsview.h"
    
    GraphicsView::GraphicsView():QGraphicsView ()
    {
        this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    }
    
    
    GraphicsView::~GraphicsView()
    {
    
    }
    
    
    // I changed there the event when wheel is moving
    bool GraphicsView::eventFilter(QObject *object, QEvent *event)
    {
        if(event->type() == QEvent::Wheel)
        {
            return  true;
        }
        return true;
    }
    
    void GraphicsView::painEvent(QPaintEvent *event)
    {
        QPainter  painter(viewport());
    
        painter.setPen(Qt::blue);
        painter.setFont(QFont("Arial", 30));
        painter.drawText(rect(), Qt::AlignCenter, "Qt");
    }
    
    

    main.cpp

    #include "graphicsview.h"
    #include <QApplication>
    #include <QGraphicsScene>
    #include <QGraphicsView>
    
    #include <QMouseEvent>
    #include <QUrl>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
    
        QRect r;
        r.setX(0);
        r.setY(0);
        r.setWidth(1920);
        r.setHeight(1080);
    
        QGraphicsScene  scene(r);
    
        GraphicsView  view;
        view.setScene(&scene);
    
        
        view.update();
        view.showFullScreen();
    
        return a.exec();
    }
    
    

    This is the errors, may be it will help:

    QWidget::paintEngine: Should no longer be called
    QPainter::begin: Paint device returned engine == 0, type: 1
    QPainter::setPen: Painter not active
    QPainter::setFont: Painter not active
    

    Can somebody help me? Thanks in advance.

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      I don't see any debug / warning output on Linux with qt5.12/13

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • S Staslend

        I saw topics of people who has the same error. I understand that all using of QPainter must happened in the paintEvent. I done this, but problem still exist.
        This is the code of function:

        void GraphicsView::painEvent(QPaintEvent *event)
        {
            QPainter  painter(viewport());
        
            painter.setPen(Qt::blue);
            painter.setFont(QFont("Arial", 30));
            painter.drawText(rect(), Qt::AlignCenter, "Qt");
        }
        

        In short, I create class that inherited from QGraphicsView. I rewrite some functions, but I do not think that problem in them. There is a full code of my program:

        GraphicsView.h

        #include <QGraphicsView>
        #include <QEvent>
        #include <QPainter>
        #include <QPaintEvent>
        
        class GraphicsView : public QGraphicsView
        {
            Q_OBJECT
        
            using  QObject :: event;
            using  QGraphicsView :: paintEvent;
        
        public:
            GraphicsView();
            virtual ~GraphicsView();
        
        
            bool eventFilter(QObject *object, QEvent *event);
            virtual void painEvent(QPaintEvent * event);
        };
        
        

        GraphicsView.cpp

        #include "graphicsview.h"
        
        GraphicsView::GraphicsView():QGraphicsView ()
        {
            this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
            this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        }
        
        
        GraphicsView::~GraphicsView()
        {
        
        }
        
        
        // I changed there the event when wheel is moving
        bool GraphicsView::eventFilter(QObject *object, QEvent *event)
        {
            if(event->type() == QEvent::Wheel)
            {
                return  true;
            }
            return true;
        }
        
        void GraphicsView::painEvent(QPaintEvent *event)
        {
            QPainter  painter(viewport());
        
            painter.setPen(Qt::blue);
            painter.setFont(QFont("Arial", 30));
            painter.drawText(rect(), Qt::AlignCenter, "Qt");
        }
        
        

        main.cpp

        #include "graphicsview.h"
        #include <QApplication>
        #include <QGraphicsScene>
        #include <QGraphicsView>
        
        #include <QMouseEvent>
        #include <QUrl>
        
        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
        
        
            QRect r;
            r.setX(0);
            r.setY(0);
            r.setWidth(1920);
            r.setHeight(1080);
        
            QGraphicsScene  scene(r);
        
            GraphicsView  view;
            view.setScene(&scene);
        
            
            view.update();
            view.showFullScreen();
        
            return a.exec();
        }
        
        

        This is the errors, may be it will help:

        QWidget::paintEngine: Should no longer be called
        QPainter::begin: Paint device returned engine == 0, type: 1
        QPainter::setPen: Painter not active
        QPainter::setFont: Painter not active
        

        Can somebody help me? Thanks in advance.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @Staslend

        I understand that all using of QPainter must happened in the paintEvent

        void GraphicsView::painEvent(QPaintEvent *event)

        Look at your typing/spelling!? (Or is that not relevant here? I assume you're trying to override?)

        1 Reply Last reply
        2
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          When re-implementing a function like that, use the override keyword. It will trigger a warning during build if no matching method can be found in one of the base class.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          3
          • SGaistS SGaist

            Hi,

            When re-implementing a function like that, use the override keyword. It will trigger a warning during build if no matching method can be found in one of the base class.

            S Offline
            S Offline
            Staslend
            wrote on last edited by
            #5

            @SGaist thank you for help, I have no errors not with QPainter. But I can't use override word with paintEvent, I have this error: 'paintEvent' marked 'override' but does not override any member function. With eventFilter it working.

            JonBJ 1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @JonB said in QWidget::paintEngine: Should no longer be called:

              painEvent

              The override keyword works, when you've the function name right.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              JonBJ 1 Reply Last reply
              3
              • S Staslend

                @SGaist thank you for help, I have no errors not with QPainter. But I can't use override word with paintEvent, I have this error: 'paintEvent' marked 'override' but does not override any member function. With eventFilter it working.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @Staslend
                http://doc.qt.io/qt-5/qgraphicsview.html#paintEvent

                void QGraphicsView::paintEvent(QPaintEvent *event)    [override virtual protected] 
                
                1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  @JonB said in QWidget::paintEngine: Should no longer be called:

                  painEvent

                  The override keyword works, when you've the function name right.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @Christian-Ehrlicher said in QWidget::paintEngine: Should no longer be called:

                  @JonB said in QWidget::paintEngine: Should no longer be called:

                  painEvent

                  The override keyword works, when you've the function name right.

                  But that's what I've been saying to the OP...! I quoted what he has written.... He is now saying he cannot use paintEvent spelt correctly with override, so I guess he needs to show us what actually tried?

                  1 Reply Last reply
                  3
                  • S Offline
                    S Offline
                    Staslend
                    wrote on last edited by
                    #9

                    Thanks for everyone! I am sorry for this mistake. The QtCreator write painEvent using Italic so I thought that the name of function was written right. Everything is working now.

                    Pablo J. RoginaP 1 Reply Last reply
                    0
                    • S Staslend

                      Thanks for everyone! I am sorry for this mistake. The QtCreator write painEvent using Italic so I thought that the name of function was written right. Everything is working now.

                      Pablo J. RoginaP Offline
                      Pablo J. RoginaP Offline
                      Pablo J. Rogina
                      wrote on last edited by
                      #10

                      @Staslend if your issue is solved, please don't forget to mark your post as such! Thanks.

                      Upvote the answer(s) that helped you solve the issue
                      Use "Topic Tools" button to mark your post as Solved
                      Add screenshots via postimage.org
                      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved