tags:

views:

36

answers:

2

Several examples on trolltech use QWidget rather than a QMainWindow as the main window for simple Qt applications.

Now I need just a simple window with a single content widget (QGlWidget) that covers the entire client area.

However, when I show a QWidget window with a single content window it automatically resizes itself to be tiny.

If I create the QWidget parent window without a child It is a nice large default size.

I don't want to resort to using Layouts for a single child window :/

+3  A: 

What I understand is that you use a QWidget to display your QGIWidget. Try calling the show method of your QGIWidget directly (if your QGIWidget class inherits QWidget), Qt will create the window decoration for you.

Otherwise if you really need your widget to be inside one another, and fit its size, you'll have to use a layout.

gregseth
Im just a bit confused. Im sure there are simple examples that use a QWidget as a container and add a QButton - the QWidget then sizes correctly.Some kind of sizing logic is being invoked - if I create an empty QWidget it creates at quite a reasonable size. Its just when I create a child QGlWidget, that it creates really really tiny.For now however im going with your suggestion, and simply use the QGlWidget as my top level widget.
Chris Becke
+1  A: 

Either follow gregseth's advice or you can simply resize the widget yourself. (though this way you'll loose nice auto-resizing which is provided by Qt when you use layouts)

In your case you can basically do something like:

QGlWidget* myWidget = new QGlWidget;
myWidget->resize(QApplication::desktopWidget()->availableGeometry().size());

// or maybe instead of resizing show it in fullscreen:
myWidget->showFullScreen();

(actually I don't remember if showFullScreen() will do resizing for you, maybe you'll need both resize+showFullScreen :))

Cheers :)

P.S. Using layout is actually an option. It's not expensive and it's flexible. All it gets: "layout = new QVBoxLayout(myWidget); layout->addWidget(myWidget);" and you're done :)

dpimka