QGraphicsView + QGLWidget problem

Steve Pike pike_steve at rocketmail.com
Thu May 31 05:17:00 UTC 2012


Hi,

My name is Steve and am new to the mailinglist. 

I've submitted a bug report to Sourceforge regarding QGraphicsView + QGLWidget under Android. BogDan asked me to join this mailinglist and discuss the bug.

For a client I am porting their Qt based software to Android, for use on Samsung Galaxy smartphones. Currently the system uses a QGraphicsScene and QGraphicsView that is accelerated using a QGLWidget as the viewport, which works fine under Ubuntu. Software is written in 100% C++, no QML.

Porting this using Necessitas is a pretty smooth operation and everything works perfectly, as long as I don't use a QGLWidget as the viewport. When I do use GL acceleration, it seems that embedded widgets created using addWidget() are resized to full screen within the QGraphicsView, resulting in one widget, for example a label, dominating the screen, the rest being invisible.

Temporarily uncommenting the code for this widget will result in another GUI element appearing full screen. Getting the dimensions from the widget and printing them to debugging output reveals that they are indeed resized to screen dimensions and I cannot override this using setGeometry.

I'm an experienced C/C++ hacker, so I will not only present my problem, but will hopefully solve it as well.

Yesterday, I found the following clues in the qandroideglfswindow.cpp and I looks like it is linked to my problem.


https://qt.gitorious.org/~taipan/qt/android-lighthouse/blobs/stable/src/plugins/platforms/android/src/opengl/qandroideglfswindow.cpp


Specifically:

void QAndroidEglFSWindow::setGeometry(const QRect &)
{
    // We only support full-screen windows
    QRect rect(m_screen->availableGeometry());
    QWindowSystemInterface::handleGeometryChange(this->widget(), rect);

    // Since toplevels are fullscreen, propegate the screen size back to the widget
    widget()->setGeometry(rect);

    QPlatformWindow::setGeometry(rect);
}


...

Qt::WindowFlags QAndroidEglFSWindow::setWindowFlags(Qt::WindowFlags type)
{ 
    flags = type;

    if (!widget()->isFullScreen() && flags != Qt::Popup && flags != Qt::Tool
&& flags != Qt::ToolTip && flags != Qt::SplashScreen)
         widget()->setWindowState(widget()->windowState() | Qt::WindowMaximized);
    return flags;
}


In alpha4 there are some more modifications to this function that have to do with maximizing widgets:

    QtAndroid::setFullScreen(widget());


I think the problem is this:

When a widget is created without a parent, for example using 'new QLabel()', the OpenGL window code makes it a full-screen top level window, even though it is not shown yet.

If later I use addWidget() to embed this widget into a QGraphicsScene, which is the normal way to go, this widget stays full screen and seems to keep its window status.
I thought the solution would be to create widgets with the QGraphicsView or a dummy widget as the parent, but this is not possible as addWidget() will not allow you to embed widgets that already have a parent.
Workarounds have failed, such as creating my GUI elements with window flags like Qt::Tool, to prevent them being made full screen, or removing the Qt::Window status after creating the widget.

These restrictions are not in the raster code. I hope anyone has some ideas about this.

Steve



Steve Pike



More information about the Necessitas-devel mailing list