rendered paste bodyESTUDO DE CASO EM QT
====== == ==== == ==
1- CRIAR DIRETÓRIO: login_dialog
2- CRIAR OS ARQUIVOS NO DIRETÓRIO: login_dialog
3- TOTAL DE ARQUIVOS: 3 ARQUIVOS.
ARQUIVO FONTE 1: login_dialog.h
---------------------- CUT HERE ----------------------
#ifndef LOGINDIALOG_H
#define LOGINDIALOG_H
#include <QDialog>
class QLabel;
class QLineEdit;
class QPushButton;
class LoginDialog: public QDialog
{
Q_OBJECT
public:
LoginDialog(QWidget *parent = 0);
private slots:
void okClicked();
void enableOkButton(const QString &text);
private:
QLabel *label;
QLineEdit *lineEdit;
QPushButton *okButton;
QPushButton *cancelButton;
};
#endif
---------------------- CUT HERE ----------------------
ARQUIVO FONTE 2: login_dialog.cpp
---------------------- CUT HERE ----------------------
#include <QtGui>
#include "login_dialog.h"
LoginDialog::LoginDialog(QWidget *parent): QDialog(parent)
{
label = new QLabel(tr("Login:"));
lineEdit = new QLineEdit;
label->setBuddy(lineEdit);
okButton = new QPushButton(tr("&Ok"));
okButton->setDefault(true);
okButton->setEnabled(false);
cancelButton = new QPushButton(tr("Cancelar"));
connect(lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(enableOkButton(const QString &)));
connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
QHBoxLayout *topLeftLayout = new QHBoxLayout;
topLeftLayout->addWidget(label);
topLeftLayout->addWidget(lineEdit);
QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addLayout(topLeftLayout);
QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout->addWidget(okButton);
rightLayout->addWidget(cancelButton);
rightLayout->addStretch();
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayout);
setLayout(mainLayout);
setWindowTitle(tr("Login"));
setFixedHeight(sizeHint().height());
}
void LoginDialog::okClicked()
{
QString text = lineEdit->text();
}
void LoginDialog::enableOkButton(const QString &text)
{
okButton->setEnabled(!text.isEmpty());
}
---------------------- CUT HERE ----------------------
ARQUIVO FONTE 3: main.cpp
---------------------- CUT HERE ----------------------
#include <QApplication>
#include "login_dialog.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
LoginDialog *dialog = new LoginDialog;
dialog->show();
return app.exec();
}
---------------------- CUT HERE ----------------------