[英]Qt QGraphicsView Event
我有一个包含我的QGraphicsView
的类View
,但是在继承它时遇到了麻烦。 我的代码如下:
class View: public QGraphicsView {//inherits qwidget -- so we can make it full screen there
Q_OBJECT
public:
View(QGraphicsScene * _scene);//this is responsible for setting up the screen and instantiating several elements
~View();
protected:
virtual void paintEvent(QPaintEvent * event) = 0;
Game
继承自View
:
#include "view.h" //this includes all of the functionality of the different elements
using namespace std;
class Game : public View {//inherit everything above and down into private functions
public:
Game(QGraphicsScene * _scene);
~Game();
protected:
void paintEvent(QPaintEvent * event);
};
我已经实现paintEvent
只是一个快速cout
的game
。 当我编译时,一切都可以编译,但是当我运行时,我不断收到一条消息,说一个纯虚函数被调用:
libc++abi.dylib: pure virtual method called
Abort trap: 6
我的View
构造函数如下所示:
View::View(QGraphicsScene * _scene) : QGraphicsView(_scene) {...
任何帮助将不胜感激。
我得到了paintEvent
函数来编译并打开我的应用程序。 但是由于某种原因,每当我尝试绘制场景时,它都不会起作用。
但是,如果我取出paintEvent
函数,它将正常工作。 关于为什么paintEvent
打破了这个的任何建议?
在我的主文件中:
QGraphicsEllipseItem * item = new QGraphicsEllipseItem(0, scene);
item->setRect(50.0, 50.0, 100.0, 100.0);
view->setRenderHints(QPainter::Antialiasing);
view->show();
如果我摆脱了虚拟的paintEvent
函数,这会起作用,但是包括它会破坏绘图的圆吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.