PDA

View Full Version : layout not being sized



jhowland
9th January 2011, 22:00
I am drawing a QGLWidget based map in a widget based main program (ie, no main window, just a widget).

When I draw my map and use a layout (call it H) to draw it into my widget, all is fine

If, however, I don't draw the map into H, but instead I make a widget that includes a QGroupBox, my map, and a couple of buttons, make a new layout (call it "V") , add the map and buttons into the layout, and then set QGroupBox layout to be "V", and then add the Groupbox to Layout H, everything compiles and runs without error--but my application shows up as a very small widget with no apparent content. When I enlarge it with the mouse, it is drawn just how I want it to be--all the buttons and map are drawn properly

my question is why isn't it drawn right the first time? I have tried explicitly setting sizes, etc, and it makes no difference. Is there something special about group boxes and layouts? Or something about a QGLWIdget?

here is the code that doesn't draw properly




NavMapWidget::NavMapWidget(IniFile *iniFile,QWidget *parent) :
QWidget(parent)
{
navMap = new NavMap(iniFile);
mapFrame = new QGroupBox;
zoomInButton = new QPushButton("Zoom in");
zoomOutButton = new QPushButton("Zoom out");
QGridLayout *widgetLayout = new QGridLayout;
widgetLayout->addWidget(navMap,0,0);
widgetLayout->addWidget(zoomInButton,1,0);
widgetLayout->addWidget(zoomOutButton,1,1);
mapFrame->setLayout(widgetLayout);

QVBoxLayout *mainMapLayout = new QVBoxLayout(this);
mainMapLayout->addWidget(mapFrame);
}

navMapWidget = new NavMapWidget(&iniFile,(QWidget *)this);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(navMapWidget);
setLayout(mainLayout);



thanks in advance

Jonathan Howland

ChrisW67
9th January 2011, 23:09
You never call QWidget::setLayout() on the NavMapWidget. mainMapLayout is left dangling, not attached to a widget.

jhowland
10th January 2011, 02:05
You never call QWidget::setLayout() on the NavMapWidget. mainMapLayout is left dangling, not attached to a widget.

but when I created the layout, I made it's parent "this", which I believe sets the layout to the widget? In any case, I added a setLayout, and it makes no difference

a further clue--when I don't add the navmap to the layout, the two buttons and the frame get drawn OK right from the start.

I looked into my resizeGL function, and it does get called several times early on (not sure why) with 0 arguments for window height, so I'm beginning to suspect the QGLWidget