首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Qt QGraphicsView事件

Qt QGraphicsView事件
EN

Stack Overflow用户
提问于 2012-10-17 17:19:41
回答 1查看 689关注 0票数 0

我有一个合并了我的QGraphicsView的类View,但是我在继承它时遇到了麻烦。我的代码如下:

代码语言:javascript
复制
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

代码语言:javascript
复制
#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);

};

我已经在game中用一个快速的cout实现了paintEvent。当我编译时,一切都可以正常编译,但当我运行时,我总是收到一条消息,说调用了一个纯虚函数:

代码语言:javascript
复制
libc++abi.dylib: pure virtual method called
Abort trap: 6

我的View构造函数如下所示:

代码语言:javascript
复制
View::View(QGraphicsScene * _scene) : QGraphicsView(_scene) {...

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2012-10-17 18:57:42

我获得了paintEvent函数来编译和打开我的应用程序。但由于某些原因,每当我试图在我的场景上绘制时,它都不起作用。

但是,如果我去掉paintEvent函数,它就能正常工作。对于paintEvent为什么会破坏这一点,有什么建议吗?

在我的主文件中:

代码语言:javascript
复制
QGraphicsEllipseItem * item = new QGraphicsEllipseItem(0, scene);

    item->setRect(50.0, 50.0, 100.0, 100.0);

    view->setRenderHints(QPainter::Antialiasing);

    view->show();

如果我去掉了虚拟的paintEvent函数,这是可行的,但是包含它会打破画出的圆吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12931016

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档