Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsScene with QGLWidget viewport is still active after closing window
Forum Updated to NodeBB v4.3 + New Features

QGraphicsScene with QGLWidget viewport is still active after closing window

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 5.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    torsten
    wrote on 12 Nov 2010, 10:31 last edited by
    #1

    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);
    }
    }@

    1 Reply Last reply
    0
    • I Offline
      I Offline
      iunknwn
      wrote on 12 Nov 2010, 17:55 last edited by
      #2

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

      Problem solved.

      Vista x64 with Qt 4.8.2 and VS2010

      1 Reply Last reply
      0
      • T Offline
        T Offline
        torsten
        wrote on 12 Nov 2010, 19:13 last edited by
        #3

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

        1 Reply Last reply
        0
        • T Offline
          T Offline
          torsten
          wrote on 13 Nov 2010, 07:36 last edited by
          #4

          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

          1 Reply Last reply
          0

          1/4

          12 Nov 2010, 10:31

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved