QWidget::paintEngine: Should no longer be called
-
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.
-
I don't see any debug / warning output on Linux with qt5.12/13
-
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. -
-
@JonB said in QWidget::paintEngine: Should no longer be called:
painEvent
The override keyword works, when you've the function name right.
-
@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 withoverride
, so I guess he needs to show us what actually tried?