Results 1 to 3 of 3

Thread: layout not being sized

  1. #1
    Join Date
    Sep 2008
    Location
    Falmouth, MA, USA
    Posts
    34
    Thanks
    4
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default layout not being sized

    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

    Qt Code:
    1. NavMapWidget::NavMapWidget(IniFile *iniFile,QWidget *parent) :
    2. QWidget(parent)
    3. {
    4. navMap = new NavMap(iniFile);
    5. mapFrame = new QGroupBox;
    6. zoomInButton = new QPushButton("Zoom in");
    7. zoomOutButton = new QPushButton("Zoom out");
    8. QGridLayout *widgetLayout = new QGridLayout;
    9. widgetLayout->addWidget(navMap,0,0);
    10. widgetLayout->addWidget(zoomInButton,1,0);
    11. widgetLayout->addWidget(zoomOutButton,1,1);
    12. mapFrame->setLayout(widgetLayout);
    13.  
    14. QVBoxLayout *mainMapLayout = new QVBoxLayout(this);
    15. mainMapLayout->addWidget(mapFrame);
    16. }
    17.  
    18. navMapWidget = new NavMapWidget(&iniFile,(QWidget *)this);
    19. QVBoxLayout *mainLayout = new QVBoxLayout;
    20. mainLayout->addWidget(navMapWidget);
    21. setLayout(mainLayout);
    To copy to clipboard, switch view to plain text mode 
    thanks in advance

    Jonathan Howland

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: layout not being sized

    You never call QWidget::setLayout() on the NavMapWidget. mainMapLayout is left dangling, not attached to a widget.

  3. #3
    Join Date
    Sep 2008
    Location
    Falmouth, MA, USA
    Posts
    34
    Thanks
    4
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: layout not being sized

    Quote Originally Posted by ChrisW67 View Post
    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

Similar Threads

  1. How to make a QMainWindow fixed sized?
    By Goldmmbr in forum Newbie
    Replies: 2
    Last Post: 18th November 2009, 08:52
  2. Creating a square sized widget in a layout
    By cboles in forum Qt Programming
    Replies: 5
    Last Post: 22nd September 2008, 23:38
  3. how to put different sized icons in a QListView
    By namume in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2008, 10:57
  4. Dynamically sized QTableWidget
    By therealjag in forum Qt Programming
    Replies: 3
    Last Post: 31st March 2006, 21:06
  5. Replies: 1
    Last Post: 18th March 2006, 10:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.