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:
#include <qapplication.h>
#include <qwidget.h>
#include <qpushbutton.h>
#include <qgridlayout.h>
Q_OBJECT
public:
gui();
private:
};
gui::gui() {
base->addWidget(pb1, 1, 0);
base->addWidget(pb2, 1, 1);
base->addWidget(pb, 0, 0, 0, 1);
}
int main(int argc, char** argv) {
gui* w = new gui();
w->show();
app.exec();
delete w;
return 0;
}
#include <qapplication.h>
#include <qwidget.h>
#include <qpushbutton.h>
#include <qgridlayout.h>
class gui : public QWidget {
Q_OBJECT
public:
gui();
private:
QPushButton* pb;
QPushButton* pb1;
QPushButton* pb2;
QGridLayout* base;
};
gui::gui() {
base = new QGridLayout(this);
pb = new QPushButton("Top");
pb1 = new QPushButton("Bottom-Left");
pb2 = new QPushButton("Bottom-Right");
base->addWidget(pb1, 1, 0);
base->addWidget(pb2, 1, 1);
base->addWidget(pb, 0, 0, 0, 1);
}
int main(int argc, char** argv) {
QApplication app(argc, argv);
gui* w = new gui();
w->show();
app.exec();
delete w;
return 0;
}
To copy to clipboard, switch view to plain text mode
Thanks.
Bookmarks