Qt 5.3 QWidget::paintEngine : Should no longer be called

时间秒杀一切 提交于 2021-02-11 12:56:54

问题


I'm moving my code from a Qt 4.x to Qt 5.3 and I am running into a weird Qt warning shown in the command prompt. There are no errors or anything but the command prompt will show the following:

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

I believe I narrowed it down to one class: Header:

#pragma once

#include <QtCore\qmetaobject.h>
#include <QtWidgets\Qwidget.h>
#include <QtWidgets\Qslider.h>
#include <Qtwidgets\Qpushbutton.h>
#include <Qtwidgets\Qcheckbox.h>
#include "MyGLWindow.h"
#include <QtWidgets\QHboxLayout>
#include <QtWidgets\QVboxLayout>
#include <QtWidgets\qmenubar.h>
#include <QtWidgets\qlabel.h>

class MeWidg : public QGLWidget
{
public:
    QTimer myTimer;
    bool testToggle;
    float testRow;
    bool noToggle;

    MyGLWindow *gameGLWindow;
    MeWidg();
private:
    void myUpdate();
    void loadModel();
};

and Source:

#include "MeWidg.h"
#include "DebugMenu.h"

MeWidg::MeWidg()
{
QVBoxLayout* mainLayout=new QVBoxLayout();
setLayout(mainLayout);

QHBoxLayout* setUpLayout=new QHBoxLayout();

setWindowTitle("Game Creator");

QHBoxLayout *game =new QHBoxLayout();
gameGLWindow=new MyGLWindow();

debugMenu.initialize(setUpLayout);
debugMenu.addLayout("World");

QMenuBar* mb=new QMenuBar();
mb->setMaximumHeight(20);

QMenu* fileMenu = mb->addMenu("File");

QAction* action;
fileMenu->addAction(action = new QAction("Load Project", this));
//action->setShortcut(QKeySequence::Open);
//connect(action, SIGNAL(triggered()), this, SLOT(loadObj()));

fileMenu->addAction(action = new QAction("Save Project", this));
//action->setShortcuts(QKeySequence::Save);
//connect(action, SIGNAL(triggered()), this, SLOT(saveNative()));

fileMenu->addSeparator();

fileMenu->addAction(action = new QAction("Load level", this));
//action->setShortcuts(QKeySequence::Save);
//connect(action, SIGNAL(triggered()), this, SLOT(loadLVL()));

fileMenu->addAction(action = new QAction("Save Level", this));
//action->setShortcuts(QKeySequence::Save);
//connect(action, SIGNAL(triggered()), this, SLOT(saveNative()));

fileMenu->addSeparator();

fileMenu->addAction(action = new QAction("Close", this));
//action->setShortcuts(QKeySequence::Save);
//connect(action, SIGNAL(triggered()), this, SLOT(saveNative()));

QMenu* objectMenu=mb->addMenu("Objects");
objectMenu->addAction(action=new QAction("Load Model", this));
//action->setShortcut(QKeySequence::Open);
connect(action, &QAction::triggered, [=]() { this->loadModel();});

objectMenu->addAction(action=new QAction("Add Light", this));
//action->setShortcut(QKeySequence::Open);
//connect(action, SIGNAL(triggered()), this, SLOT(loadObj()));

objectMenu->addAction(action=new QAction("Add Sound", this));
//action->setShortcut(QKeySequence::Open);
//connect(action, SIGNAL(triggered()), this, SLOT(loadObj()));

objectMenu->addAction(action=new QAction("Add Game Object", this));
//action->setShortcut(QKeySequence::Open);
//connect(action, SIGNAL(triggered()), this, SLOT(loadObj()));

mainLayout->addWidget(mb);

game -> addWidget(gameGLWindow,1, 0);
setUpLayout -> addLayout(game);
gameGLWindow->setMinimumHeight(600);
gameGLWindow->setMinimumWidth(500);

mainLayout->addLayout(setUpLayout, 1);

connect(&myTimer, &QTimer::timeout, [=]() { this->myUpdate(); });
myTimer.start(16);
}

void MeWidg::myUpdate()
{
debugMenu.update();

if(GetAsyncKeyState(VK_ESCAPE) && !noToggle)
{
    noToggle=true;
    debugMenu.toggleVisibility();
}
else if(!GetAsyncKeyState(VK_ESCAPE) && noToggle)
{
    noToggle=false;
}
}

void MeWidg::loadModel()
{
gameGLWindow->loadModel();
}

Would anyone know why I am getting these warnings? Also none of the widgets I have been using are showing up, the only thing that shows up is a blank box where the layouts used to be. If I can't figure this out I will prolly just go back to qt 4.x.


回答1:


You are not showing the relevant part of your code. There seems to be some custom widget that calls the paintEngine() method on it's base class (which is not allowed). Find that widget by finding the paintEngine() call and fix it.



来源:https://stackoverflow.com/questions/26306391/qt-5-3-qwidgetpaintengine-should-no-longer-be-called

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!