簡體   English   中英

Qt QGraphicsView事件

[英]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只是一個快速coutgame 當我編譯時,一切都可以編譯,但是當我運行時,我不斷收到一條消息,說一個純虛函數被調用:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM