範例1:增加按鈕(Push Button),水平排版
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;
button1 = new QPushButton(tr("YES"));
button2 = new QPushButton(tr("NO"));
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
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
顯示結果:
沒有留言:
張貼留言