QGraphicsScene with QGLWidget viewport is still active after closing window



  • Hello,

    I have a problem with a QGraphicsScene, i want to use it in fullscreen mode. But if i use an QGLWidget as viewport, the screen stays black, even if the parent window is already closed. If i don't use the fullscreen, it works. I've wrote a little demoproject (source below) you can download "here":http://projects.ideaplexus.com/attachments/download/10/DemoProjekt.zip if you want to try it. I don't get the problem.

    main.cpp
    @#include "demodialog.h"

    #include <QtGui/QApplication>
    #include <QWidget>

    int main( int argc, char* argv[] ) {
    QApplication app( argc, argv );
    DemoDialog *demoDialog = new DemoDialog();
    demoDialog->show();
    return app.exec();
    }@

    demodialog.h
    @#ifndef DEMODIALOG_H
    #define DEMODIALOG_H

    #include <QDialog>
    #include "graphicswidgetdialog.h"

    class DemoDialog : public QDialog
    {
    Q_OBJECT
    public:
    explicit DemoDialog(QWidget *parent = 0);
    ~DemoDialog();

    private:
    GraphicsWidgetDialog *gwd;

    private slots:
    void normalDialog();
    void fullDialog();
    void closeDialog();
    };

    #endif // DEMODIALOG_H@

    demodialog.cpp
    @#include "demodialog.h"
    #include <QHBoxLayout>
    #include <QPushButton>

    DemoDialog::DemoDialog(QWidget *parent) :
    QDialog(parent)
    {
    gwd = new GraphicsWidgetDialog;
    QPushButton *normal = new QPushButton(tr("normal"));
    QPushButton *full = new QPushButton(tr("fullscreen"));
    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(normal);
    layout->addWidget(full);
    setLayout(layout);
    connect(normal,SIGNAL(clicked()),this,SLOT(normalDialog()));
    connect(full,SIGNAL(clicked()),this,SLOT(fullDialog()));
    connect(gwd,SIGNAL(closeDialog()),this,SLOT(closeDialog()));
    }

    DemoDialog::~DemoDialog() {
    }

    void DemoDialog::normalDialog() {
    gwd->showNormal();
    }

    void DemoDialog::fullDialog() {
    gwd->showFullScreen();
    }

    void DemoDialog::closeDialog() {
    gwd->close();
    }@

    graphicswidgetdialog.h
    @#ifndef GRAPHICSWIDGETDIALOG_H
    #define GRAPHICSWIDGETDIALOG_H

    #include <QDialog>
    #include "graphicswidget.h"

    class GraphicsWidgetDialog : public QDialog
    {
    Q_OBJECT
    public:
    explicit GraphicsWidgetDialog(QWidget *parent = 0);
    ~GraphicsWidgetDialog();

    private:
    GraphicsWidget *graphicsWidget;

    signals:
    void closeDialog();

    private slots:
    void keyPressEventSuccess();

    };

    #endif // GRAPHICSWIDGETDIALOG_H@

    graphicswidgetdialog.cpp
    @#include "graphicswidgetdialog.h"
    #include <QHBoxLayout>

    GraphicsWidgetDialog::GraphicsWidgetDialog(QWidget *parent) :
    QDialog(parent)
    {
    graphicsWidget = new GraphicsWidget(this);
    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(graphicsWidget);
    layout->setContentsMargins(0,0,0,0);
    setLayout(layout);
    connect(graphicsWidget,SIGNAL(keyPressEventSuccess()),this,SLOT(keyPressEventSuccess()));
    }

    GraphicsWidgetDialog::~GraphicsWidgetDialog() {
    }

    void GraphicsWidgetDialog::keyPressEventSuccess() {
    emit closeDialog();
    }@

    graphicswidget.h
    @#ifndef GRAPHICSWIDGET_H
    #define GRAPHICSWIDGET_H

    #include <QWidget>
    #include <QGraphicsScene>
    #include <QGraphicsView>
    #include <QKeyEvent>

    class GraphicsWidget : public QWidget
    {
    Q_OBJECT
    public:
    explicit GraphicsWidget(QWidget *parent = 0);
    ~GraphicsWidget();

    private:
    QGraphicsScene *scene;
    QGraphicsView *view;
    bool listenEvents;

    protected:
    void keyPressEvent(QKeyEvent *event);

    signals:
    void keyPressEventSuccess();
    };

    #endif // GRAPHICSWIDGET_H@

    graphicswidget.cpp
    @#include "graphicswidget.h"
    #include <QGLWidget>
    #include <QHBoxLayout>

    GraphicsWidget::GraphicsWidget(QWidget *parent) :
    QWidget(parent)
    {
    scene = new QGraphicsScene;
    view = new QGraphicsView(scene);
    view->setViewport(new QGLWidget(QGLFormat(QGL::DirectRendering)));
    view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    view->setFrameStyle(QFrame::NoFrame);
    view->setBackgroundBrush(Qt::black);
    view->setRenderHints(QPainter::Antialiasing);
    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(view);
    layout->setContentsMargins(0,0,0,0);
    setLayout(layout);
    listenEvents=true;
    grabKeyboard();
    }

    GraphicsWidget::~GraphicsWidget() {
    }

    void GraphicsWidget::keyPressEvent(QKeyEvent *event) {
    if (listenEvents) {
    switch (event->key()) {
    case Qt::Key_F11:
    emit keyPressEventSuccess();
    break;
    default:
    QWidget::keyPressEvent(event);
    }
    } else {
    QWidget::keyPressEvent(event);
    }
    }@



  • Memory leak at demoDialog.cpp:8:
    gwd = new GraphicsWidgetDialog;
    Change to:
    gwd = new GraphicsWidgetDialog(this);

    Problem solved.



  • Dammit, you don't believe how long i'm seaching for this... tanks



  • mmh, yesterday it works, but now it seems there is another problem. I've added some debug output and i found out, that GraphicsWidget in showFullScreen don't have focus/isactivewindow. so the problem exists


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.