1. Helloworld.pro
TARGET = helloworld
SOURCES += main.cpp \
layoutdlg.cpp
HEADERS += \
layoutdlg.h
FORMS += dialog.ui
2. main.cpp
#include <QtGui>
#include <QtCore>
#include "layoutdlg.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
layoutdlg helloworld;
helloworld.show();
return app.exec();
}
#include <QtGui>
#include "layoutdlg.h"
layoutdlg::layoutdlg(QDialog *parent)
: QDialog(parent)
{
QPushButton *button1, *button2, *button3, *button4;
button1 = new QPushButton(tr("1"));
button2 = new QPushButton(tr("2"));
button3 = new QPushButton(tr("3"));
button4 = new QPushButton(tr("4"));
QGridLayout *layout = new QGridLayout;
layout->addWidget(button1, 0, 0);
layout->addWidget(button2, 0, 1);
layout->addWidget(button3, 1, 0);
layout->addWidget(button4, 1, 1);
setLayout(layout);
}
#ifndef LAYOUTDLG_H
#define LAYOUTDLG_H
#include <QDialog>
class QPushButton;
class layoutdlg : public QDialog
{
Q_OBJECT
public:
layoutdlg(QDialog *parent = 0);
};
#endif // LAYOUTDLG_H
顯示結果:
沒有留言:
張貼留言