<pre name="code" class="cpp">这是头文件
<pre name="code" class="cpp">#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QSlider>
#include <QDebug>
#include <QSpinBox>
#include <QPushButton>
#include <QLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QGroupBox>
#include <QAction>
#include <QLineEdit>
#include <QIcon>
#include "Login.h"
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
private:
Login *login;
QLineEdit *name;
QLineEdit *password ;
private slots:
void return_State();
void login_false();
void login_ok();
signals:
void get_name(QString name,QString password);
};
#endif // WIDGET_H
这是第一个例子
#include "widget.h"
#include <QMessageBox>
#include <QBoxLayout>
#include <QFormLayout>
#include <QLabel>
#include <QCheckBox>
QLabel *label_find = new QLabel(tr("Find &what: "));
QLineEdit *lineEdit_find = new QLineEdit();
label_find->setBuddy(lineEdit_find);
QCheckBox* checkBox_match = new QCheckBox(tr("Match &case"));
QCheckBox* checkbox_search = new QCheckBox(tr("Search &backford"));
QPushButton* pushbutton_find = new QPushButton(tr("&Find"));
pushbutton_find->setDefault(true);
pushbutton_find->setEnabled(false);
QPushButton* pushbutton_close =new QPushButton(tr("Close"));
QHBoxLayout *topLeftLayout = new QHBoxLayout;
topLeftLayout->addWidget(label_find);
topLeftLayout->addWidget(lineEdit_find);
QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addLayout(topLeftLayout);
leftLayout->addWidget(checkBox_match);
leftLayout->addWidget(checkbox_search);
QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout->addWidget(pushbutton_find);
rightLayout->addWidget(pushbutton_close);
rightLayout->addStretch();//添加弹簧将上面的布局顶上去
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayout);
setLayout(mainLayout);
setFixedHeight(sizeHint().height());
这是第二个
QIcon *icon = new QIcon("/image/User.png");
QFormLayout* formlayout_main = new QFormLayout(this);
// QHBoxLayout *layout_h = new QHBoxLayout(this);
QVBoxLayout* layout_v = new QVBoxLayout(this);
// QBoxLayout *layoyt_box = new QBoxLayout(dir, parent = 0);
// QGridLayout *layout1 =new QGridLayout(this);
// layout1->addWidget(button,5,5,5,1);
QLabel *username = new QLabel();
QLabel *pwd = new QLabel("密码:");
name = new QLineEdit();
password = new QLineEdit();
formlayout_main->addRow(username);
QPushButton *button_login = new QPushButton("login");
QPushButton *button_quit = new QPushButton("quit");
// layout_v->addWidget(username);
// layout_v->addWidget(name);
formlayout_main->addRow("用户名:",name);
formlayout_main->addRow("密码:",password);
formlayout_main->addRow(button_quit,button_login);
QSpinBox *spinBox = new QSpinBox;
QSlider *slider = new QSlider(Qt::Horizontal);
spinBox->setRange(0, 200);
slider->setRange(0, 200);
formlayout_main->addRow(spinBox);
formlayout_main->addRow(slider);
this->resize( 200,600);
login = new Login(this);
connect(slider, SIGNAL(valueChanged(int)), spinBox, SLOT(setValue(int)));
connect(spinBox, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
connect(button_login,SIGNAL(clicked()),this,SLOT(return_State()));
connect(this,SIGNAL(get_name(QString,QString)),login,SLOT(verfiy_login(QString,QString)));
slider->setValue(100);
this->setFixedSize(sizeHint());