PDA

View Full Version : Issues with QGridLayout



jazzyeagle
7th November 2010, 20:49
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:



#include "rbk_dlg_newrulebook.h"

RBK_DLG_NewRulebook::RBK_DLG_NewRulebook(QWidget *parent) : QDialog(parent) {
setModal(true);

grid = new QGridLayout(this);

rbnew = new QRadioButton(tr("Create New Game"), this);
grid->addWidget(rbnew, 0, 1, 2, 1);

rbexisting = new QRadioButton(tr("Use Existing Game"), this);
grid->addWidget(rbexisting, 0, 3, 2, 1);

QLabel *label1 = new QLabel(tr("Select Game"), this);
grid->addWidget(label1, 1, 0, 1, 1);

gamename = new QComboBox(this);
gamename->addItem(tr("D&D 3.5"));
gamename->addItem(tr("FFRPG 3rd Edition"));
gamename->addItem(tr("Shadowrun 3rd Edition"));
grid->addWidget(gamename, 2, 1, 3, 1);
gamename->adjustSize();

core = new QCheckBox(tr("core"), this);
grid->addWidget(core, 2, 4, 1, 1);

QLabel *label2 = new QLabel(tr("Rulebook Name:"), this);
grid->addWidget(label2, 4, 0, 1, 1);

rulebook = new QLineEdit(this);
grid->addWidget(rulebook, 4, 1, 4, 1);
rulebook->adjustSize();

setLayout(grid);
show();
}


The header looks like this:



#ifndef RBK_DLG_NEWRULEBOOK_H
#define RBK_DLG_NEWRULEBOOK_H

#include <Qt>
#include <QtGui>

class RBK_DLG_NewRulebook : public QDialog
{
public:
RBK_DLG_NewRulebook(QWidget *parent);
private:
QGridLayout *grid;
QRadioButton *rbnew, *rbexisting;
QComboBox *gamename;
QCheckBox *core;
QLineEdit *rulebook;
QPushButton *ok, *cancel;
};

#endif // RBK_DLG_NEWRULEBOOK_H


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!!

Zlatomir
7th November 2010, 21:11
The code should be:


grid->addWidget(gamename, 2, 1, 1, 3);
//...
grid->addWidget(rulebook, 4, 1, 1, 4);

jazzyeagle
7th November 2010, 22:12
I officially feel like an idiot now. Thank you so much!!