Well, I'm using QDialog, not QMainWindow, but yeah, it'll be easier to explain on code, here is it:
main.cpp:
#include <QApplication>
#include "LoginInterface.h"
int main(int argc, char *argv[])
{
LoginInterface li;
li.show();
return app.exec();
}
#include <QApplication>
#include "LoginInterface.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
LoginInterface li;
li.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
LoginInterface.cpp:
#include "LoginInterface.h"
LoginInterface
::LoginInterface(QWidget *parent, Qt
::WindowFlags flags
) :{
// GUI Controls
UserLabel
= new QLabel(tr
("User:"));
PasswordLabel
= new QLabel(tr
("Password:"));
connect(LoginButton, SIGNAL(clicked()), this, SLOT(Login()));
connect(ExitButton, SIGNAL(clicked()), this, SLOT(Exit()));
// Adding Widgets
MainLayout->addWidget(UserLabel);
MainLayout->addWidget(UserInput);
MainLayout->addWidget(PasswordLabel);
MainLayout->addWidget(PasswordInput);
MainLayout->addWidget(LoginButton);
MainLayout->addWidget(ExitButton);
// Display
setLayout(MainLayout);
setWindowTitle("Login");
}
void LoginInterface::Run()
{
// Totalny rozpierdol!
delete UserLabel;
delete UserInput;
delete PasswordLabel;
delete PasswordInput;
delete LoginButton;
delete ExitButton;
// Title
data[1].clear();
data[1] = "Logged as " + data[0];
setWindowTitle(data[1]);
data[1].clear();
// Basic Tab
// // Basic Tab - Kontrolki
UsernameLabel
= new QLabel("User:");
UsernameEdit->setReadOnly(true);
data[0].clear();
// // Basic Tab - Dodawanie Widgetow
BasicLayout->addWidget(UsernameLabel);
BasicLayout->addWidget(UsernameEdit);
// // Basic Tab - Ustawianie Layoutu
BasicWidget->setLayout(BasicLayout);
// Tabs
Tabs->addTab(BasicWidget, tr("Basic Info"));
MainLayout->addWidget(Tabs);
}
void LoginInterface::Login()
{
data[0] = UserInput->text();
data[1] = PasswordInput->text();
Box->setWindowTitle("Login");
if(data[0] != "Diath" && data[1] != "test") // have to see QMySQLDriver later
{
Box->setText("You did enter wrong login data.");
}
else
{
Box->setText("Welcome!");
Run();
}
Box->exec();
}
void LoginInterface::Exit()
{
exit(0);
}
#include "LoginInterface.h"
LoginInterface::LoginInterface(QWidget *parent, Qt::WindowFlags flags) :
QDialog(parent, flags)
{
MainLayout = new QGridLayout;
// GUI Controls
UserLabel = new QLabel(tr("User:"));
UserInput = new QLineEdit;
PasswordLabel = new QLabel(tr("Password:"));
PasswordInput = new QLineEdit;
LoginButton = new QPushButton(tr("Login"));
ExitButton = new QPushButton(tr("Exit"));
connect(LoginButton, SIGNAL(clicked()), this, SLOT(Login()));
connect(ExitButton, SIGNAL(clicked()), this, SLOT(Exit()));
// Adding Widgets
MainLayout->addWidget(UserLabel);
MainLayout->addWidget(UserInput);
MainLayout->addWidget(PasswordLabel);
MainLayout->addWidget(PasswordInput);
MainLayout->addWidget(LoginButton);
MainLayout->addWidget(ExitButton);
// Display
setLayout(MainLayout);
setWindowTitle("Login");
}
void LoginInterface::Run()
{
// Totalny rozpierdol!
delete UserLabel;
delete UserInput;
delete PasswordLabel;
delete PasswordInput;
delete LoginButton;
delete ExitButton;
// Title
data[1].clear();
data[1] = "Logged as " + data[0];
setWindowTitle(data[1]);
data[1].clear();
// Basic Tab
BasicWidget = new QWidget;
BasicLayout = new QGridLayout;
// // Basic Tab - Kontrolki
UsernameLabel = new QLabel("User:");
UsernameEdit = new QLineEdit(data[0]);
UsernameEdit->setReadOnly(true);
data[0].clear();
// // Basic Tab - Dodawanie Widgetow
BasicLayout->addWidget(UsernameLabel);
BasicLayout->addWidget(UsernameEdit);
// // Basic Tab - Ustawianie Layoutu
BasicWidget->setLayout(BasicLayout);
// Tabs
Tabs = new QTabWidget;
Tabs->addTab(BasicWidget, tr("Basic Info"));
MainLayout->addWidget(Tabs);
}
void LoginInterface::Login()
{
data[0] = UserInput->text();
data[1] = PasswordInput->text();
QMessageBox *Box = new QMessageBox;
Box->setWindowTitle("Login");
if(data[0] != "Diath" && data[1] != "test") // have to see QMySQLDriver later
{
Box->setText("You did enter wrong login data.");
Box->setIcon(QMessageBox::Critical);
Box->setStandardButtons(QMessageBox::Ok);
}
else
{
Box->setText("Welcome!");
Box->setIcon(QMessageBox::Information);
Box->setStandardButtons(QMessageBox::Ok);
Run();
}
Box->exec();
}
void LoginInterface::Exit()
{
exit(0);
}
To copy to clipboard, switch view to plain text mode
LoginInterface.h:
#ifndef LOGININTERFACE_H
#define LOGININTERFACE_H
#include <QtGui>
#include <QDialog>
class LoginInterface
: public QDialog{
Q_OBJECT
public:
LoginInterface
(QWidget *parent
= 0, Qt
::WindowFlags flags
= 0);
public slots:
void Login();
void Exit();
private:
void Run();
// Main Layout and its controls.
QLabel *UserLabel,
*PasswordLabel;
// Client Layouts and their controls.
// Basic Tab
};
#endif // LOGININTERFACE_H
#ifndef LOGININTERFACE_H
#define LOGININTERFACE_H
#include <QtGui>
#include <QDialog>
class LoginInterface : public QDialog
{
Q_OBJECT
public:
LoginInterface(QWidget *parent = 0, Qt::WindowFlags flags = 0);
public slots:
void Login();
void Exit();
private:
void Run();
QString data[2];
// Main Layout and its controls.
QGridLayout *MainLayout;
QLabel *UserLabel, *PasswordLabel;
QLineEdit *UserInput, *PasswordInput;
QPushButton *LoginButton, *ExitButton;
// Client Layouts and their controls.
QGridLayout *BasicLayout;
QWidget *BasicWidget;
QTabWidget *Tabs;
// Basic Tab
QLabel *UsernameLabel;
QLineEdit *UsernameEdit;
};
#endif // LOGININTERFACE_H
To copy to clipboard, switch view to plain text mode
Now, I want to delete MainLayout while deleting old controls like UserInput, and then I have to replace this one:
MainLayout->addWidget(Tabs);
MainLayout->addWidget(Tabs);
To copy to clipboard, switch view to plain text mode
With something that will set Tabs widget as parent windows "central widget", also I have to access somehow to parent window and set its size.
Bookmarks