Here is a quick and short example of how I made a QDialog based on your picture.
dialog.h:
#ifndef DIALOG_H
#define DIALOG_H
#include <QLineEdit>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QSizePolicy>
#include <QDialog>
{
Q_OBJECT
public:
explicit Dialog
(QWidget *parent
= 0);
~Dialog();
private:
};
#endif // DIALOG_H
#ifndef DIALOG_H
#define DIALOG_H
#include <QLineEdit>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QSizePolicy>
#include <QDialog>
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
private:
QVBoxLayout *layout;
QGridLayout *lineLayout;
QPushButton *buton;
};
#endif // DIALOG_H
To copy to clipboard, switch view to plain text mode
dialog.cpp:
#include "dialog.h"
lineLayout
->addWidget
(new QLabel("Name"),
0,
0);
layout->addLayout(lineLayout);
layout->addWidget(buton,0,Qt::AlignHCenter); //here I added it to the QVBoxLayout with stretch=0 and qt alignment...more info you can get on QVBoxLayout's page
setLayout(layout);
}
Dialog::~Dialog(){
}
#include "dialog.h"
Dialog::Dialog(QWidget *parent):QDialog(parent){
layout=new QVBoxLayout;
lineLayout=new QGridLayout;
buton=new QPushButton("Ok");
lineLayout->addWidget(new QLabel("Name"),0,0);
lineLayout->addWidget(new QLineEdit,0,1);
layout->addLayout(lineLayout);
layout->addWidget(buton,0,Qt::AlignHCenter); //here I added it to the QVBoxLayout with stretch=0 and qt alignment...more info you can get on QVBoxLayout's page
setLayout(layout);
}
Dialog::~Dialog(){
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include "dialog.h"
#include <QApplication>
int main(int argc, char *argv[])
{
Dialog w;
w.show();
return a.exec();
}
#include "dialog.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Hope this helps.
Bookmarks