Results 1 to 3 of 3

Thread: Issues with QGridLayout

  1. #1
    Join Date
    Nov 2010
    Location
    Thornton, CO
    Posts
    3
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Issues with QGridLayout

    Hey, people. I'm new to Qt programming (as in I started yesterday). I have experience with some other GUI Toolkits, so for the most part it has been a relatively easy transition thus far.

    I am, however, coming across something that is yielding different results than I was expecting when it comes to the QGridLayout. I'm hoping this is an easy and obvious n00b error, but I can't seem to figure out where I'm erroring. I haven't found any other posts that describe this specific issue.

    Here's the .cpp code:

    Qt Code:
    1. #include "rbk_dlg_newrulebook.h"
    2.  
    3. RBK_DLG_NewRulebook::RBK_DLG_NewRulebook(QWidget *parent) : QDialog(parent) {
    4. setModal(true);
    5.  
    6. grid = new QGridLayout(this);
    7.  
    8. rbnew = new QRadioButton(tr("Create New Game"), this);
    9. grid->addWidget(rbnew, 0, 1, 2, 1);
    10.  
    11. rbexisting = new QRadioButton(tr("Use Existing Game"), this);
    12. grid->addWidget(rbexisting, 0, 3, 2, 1);
    13.  
    14. QLabel *label1 = new QLabel(tr("Select Game"), this);
    15. grid->addWidget(label1, 1, 0, 1, 1);
    16.  
    17. gamename = new QComboBox(this);
    18. gamename->addItem(tr("D&D 3.5"));
    19. gamename->addItem(tr("FFRPG 3rd Edition"));
    20. gamename->addItem(tr("Shadowrun 3rd Edition"));
    21. grid->addWidget(gamename, 2, 1, 3, 1);
    22. gamename->adjustSize();
    23.  
    24. core = new QCheckBox(tr("core"), this);
    25. grid->addWidget(core, 2, 4, 1, 1);
    26.  
    27. QLabel *label2 = new QLabel(tr("Rulebook Name:"), this);
    28. grid->addWidget(label2, 4, 0, 1, 1);
    29.  
    30. rulebook = new QLineEdit(this);
    31. grid->addWidget(rulebook, 4, 1, 4, 1);
    32. rulebook->adjustSize();
    33.  
    34. setLayout(grid);
    35. show();
    36. }
    To copy to clipboard, switch view to plain text mode 

    The header looks like this:

    Qt Code:
    1. #ifndef RBK_DLG_NEWRULEBOOK_H
    2. #define RBK_DLG_NEWRULEBOOK_H
    3.  
    4. #include <Qt>
    5. #include <QtGui>
    6.  
    7. class RBK_DLG_NewRulebook : public QDialog
    8. {
    9. public:
    10. RBK_DLG_NewRulebook(QWidget *parent);
    11. private:
    12. QGridLayout *grid;
    13. QRadioButton *rbnew, *rbexisting;
    14. QComboBox *gamename;
    15. QCheckBox *core;
    16. QLineEdit *rulebook;
    17. QPushButton *ok, *cancel;
    18. };
    19.  
    20. #endif // RBK_DLG_NEWRULEBOOK_H
    To copy to clipboard, switch view to plain text mode 

    I attached an image of the result I'm receiving. As you can see, the QComboBox and the QLineEdit don't extend as far as I was trying to tell the Layout. My anticipated result is for the QComboBox to fit all the way up to the QCheckBox labeled "core", and the QLineEdit to extend all the way across the dialog box.

    Can someone look at this and let me know what I'm doing wrong? Thanks!!
    Attached Images Attached Images

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Issues with QGridLayout

    The code should be:
    Qt Code:
    1. grid->addWidget(gamename, 2, 1, 1, 3);
    2. //...
    3. grid->addWidget(rulebook, 4, 1, 1, 4);
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Zlatomir for this useful post:

    jazzyeagle (7th November 2010)

  4. #3
    Join Date
    Nov 2010
    Location
    Thornton, CO
    Posts
    3
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Issues with QGridLayout

    I officially feel like an idiot now. Thank you so much!!

Similar Threads

  1. Trying to refresh a QGridLayout
    By zlacelle in forum Qt Programming
    Replies: 5
    Last Post: 5th April 2009, 21:21
  2. QGridLayOut
    By Rakesh_Kumar in forum Qt Programming
    Replies: 2
    Last Post: 9th January 2009, 04:49
  3. Delete a QGridLayout and New QGridLayout at runtime
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 5th November 2007, 13:01
  4. Qt 3.3 QGridLayout
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 23rd February 2007, 17:40
  5. QGridLayout
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 29th June 2006, 20:34

Tags for this Thread

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.