Results 1 to 4 of 4

Thread: QGridLayout woes

  1. #1
    Join Date
    Oct 2006
    Posts
    5
    Qt products
    Qt4

    Default QGridLayout woes

    I'm not exactly new to Qt, I've written 2-3 decent programs that use it before, but this is the first time I've used Qt4 and I'm having some basic layout problems.

    I'm trying to create a single window with a 2x2 grid, where the top row is merged together and has a single push button titles "Top". The lower row should have one push button per cell, "Bottom-Left" and "Bottom-Right".

    The problem is the top button does not appear to be expanding along both columns as it should. It also seems the QGridLayout is ignoring the second row -- while that row is being rendered, it overlaps the first and does not appear to be properly spaced.

    Has the method of doing this changed since Qt3?

    Here's the code:
    Qt Code:
    1. #include <qapplication.h>
    2.  
    3. #include <qwidget.h>
    4. #include <qpushbutton.h>
    5. #include <qgridlayout.h>
    6.  
    7. class gui : public QWidget {
    8. Q_OBJECT
    9.  
    10. public:
    11. gui();
    12.  
    13. private:
    14.  
    15. QGridLayout* base;
    16. };
    17.  
    18. gui::gui() {
    19. base = new QGridLayout(this);
    20.  
    21. pb = new QPushButton("Top");
    22. pb1 = new QPushButton("Bottom-Left");
    23. pb2 = new QPushButton("Bottom-Right");
    24.  
    25. base->addWidget(pb1, 1, 0);
    26. base->addWidget(pb2, 1, 1);
    27. base->addWidget(pb, 0, 0, 0, 1);
    28. }
    29.  
    30. int main(int argc, char** argv) {
    31.  
    32. QApplication app(argc, argv);
    33.  
    34.  
    35.  
    36. gui* w = new gui();
    37.  
    38.  
    39.  
    40. w->show();
    41.  
    42.  
    43.  
    44. app.exec();
    45.  
    46.  
    47.  
    48. delete w;
    49.  
    50. return 0;
    51.  
    52. }
    To copy to clipboard, switch view to plain text mode 

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGridLayout woes

    Quote Originally Posted by para View Post
    base->addWidget(pb, 0, 0, 0, 1);
    It works with "base->addWidget(pb, 0, 0, 1, 0);". It looks like rowSpan and columnSpan parameters are switched.

  3. #3
    Join Date
    Oct 2006
    Posts
    5
    Qt products
    Qt4

    Default Re: QGridLayout woes

    I can't believe I didn't notice that! Thanks a lot.
    I seem to remember Qt3's parameters being (fromRow, toRow, FromCol, toCol) -- really had me stumped.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGridLayout woes

    Quote Originally Posted by para View Post
    I seem to remember Qt3's parameters being (fromRow, toRow, FromCol, toCol)
    In Qt4 they are (fromRow, fromCol, rowSpan, colSpan), so actually it should be:
    Qt Code:
    1. base->addWidget(pb, 0, 0, 1, 2)
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. MySql Stored Procedures Woes
    By stevey in forum Qt Programming
    Replies: 9
    Last Post: 19th October 2006, 12:58
  2. Plugin woes
    By stevey in forum Qt Programming
    Replies: 8
    Last Post: 24th July 2006, 01:30
  3. QGridLayout
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 29th June 2006, 20:34
  4. QPixmap and QGridLayout
    By Talon_Karrde in forum Qt Programming
    Replies: 5
    Last Post: 22nd February 2006, 12:27

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.