четверг, 5 августа 2021 г.

Login Password Project

Login Password project

(Gui Programming)


1. LoginPassword.pro


QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    
# disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    secDialog.cpp \
    widget.cpp

HEADERS += \
    secDialog.h \
    widget.h

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target



2. Headers - widget.h


#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QLineEdit>
#include <QPushButton>

#include"secDialog.h"

class Widget : public QWidget
{
    Q_OBJECT  //macros object

public:
    Widget(QWidget * parent = 0);

private slots:
    void onPushButtonLoginClicked();
    void onQuitMessage();

private:
    QLineEdit *username;
    QLineEdit *password;
    QPushButton *login;
    QPushButton *cancel;
};

#endif // WIDGET_H



3. Headers - secDialog.h


#ifndef SECDIALOG_H
#define SECDIALOG_H

#include <QDialog>
#include <QTextEdit>
#include <QLabel>

class secDialog : public QDialog
{
    Q_OBJECT

public:
     secDialog();

private:
    QLabel *text;

};

#endif // SECDIALOG_H



4. Sources - main.cpp


#include "widget.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();

    w.setWindowTitle("Login");

    return a.exec();
}



5. Sources - widget.cpp


#include "widget.h"

#include <QVBoxLayout>
#include <QMessageBox>

Widget::Widget(QWidget * parent) : QWidget(parent)
{
    username = new QLineEdit();
    username->setStyleSheet("color : rgb(140, 0, 140, 250)}");
    username -> setPlaceholderText("Username");

    password = new QLineEdit();
    password->setEchoMode(QLineEdit::Password);
    password->setStyleSheet("color : rgb(150, 0, 150, 250)}");
    password -> setPlaceholderText("Password");

    login = new QPushButton("Login");
    cancel = new QPushButton ("Close");


    QVBoxLayout * lyt = new QVBoxLayout(this);
    lyt->addWidget(username);
    lyt->addWidget(password);
    lyt->addWidget(login);
    lyt->addWidget(cancel);
    setLayout(lyt);


    connect(login, SIGNAL(clicked()), this,
 SLOT(onPushButtonLoginClicked()));
    connect(cancel, SIGNAL(clicked()), this, SLOT(onQuitMessage()));

    setFixedWidth(225);
    setFixedHeight(150);

}


void Widget::onPushButtonLoginClicked()
{
    QString userText = username->text();
    QString passwordText = password ->text();


    if(userText == "gui" && passwordText == "programming")  

    {

                close();  //username, password window is closing
                secDialog secdialog;
                secdialog.setModal(true);   //main page
                secdialog.exec();
    }
    else
    {
     QMessageBox::warning(this,"Login",
                          "Username and password is not correct");
    }
}



void Widget::onQuitMessage()
  {
    int o = QMessageBox::question(this, "Exit", "Are u sure to exit?",
                                  QMessageBox::Yes, QMessageBox::No);
    if (o == QMessageBox::Yes)
    {
      this->close();
    }

   }



6. Sources - secDialog.cpp


#include "secDialog.h"
#include <QVBoxLayout>

secDialog::secDialog()
{

    setFixedWidth(225);   //laynutyuny fix
    setFixedHeight(150);

    text = new QLabel("This is your page");
    text->setStyleSheet("color : rgb(238, 130, 238, 255)}");

    QVBoxLayout *vlyt = new QVBoxLayout();
    vlyt->addWidget(text);
    setLayout(vlyt);

}



Result:



































среда, 4 августа 2021 г.

Todolist project

ToDoList project (Gui Programming)


1. ToDoList.pro


QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    
# disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    todolist.cpp

HEADERS += \
    todolist.h

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

RESOURCES += \
    images.qrc



2. Header - todolist.h


#ifndef CTODOLIST_H
#define CTODOLIST_H

#include <QMainWindow>
#include <QListView>
#include <QStringListModel>
#include <QPushButton>

class CToDoList : public QMainWindow
{
    Q_OBJECT

public:
    CToDoList(QWidget *parent = 0);

private slots:
        void onAddPressed();
        void onRemovePressed();
        void onDreamButtonPressed();

private:
    QListView * leftList = 0;
    QListView * rightList = 0;
    QAction * add = 0;
    QAction * remove = 0;
    QPushButton * dreamButton =0;
};

#endif // CTODOLIST_H



3. Sources - main.cpp


#include "todolist.h"

#include <QApplication>
#include<QSplashScreen>
#include<QTimer>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    CToDoList w;
    w.show();

    w.setWindowTitle("My To Do List");


    QSplashScreen * splash = new QSplashScreen;
    splash ->setPixmap(QPixmap(":/icon/listpic.jpg"));
    splash ->show();
    QTimer::singleShot(2000, splash, SLOT(close()));
    QTimer::singleShot(2000, &w, SLOT(show()));

    return a.exec();
}



4. Sources - todolist.cpp


#include "todolist.h"

#include <QLabel>
#include <QToolBar>
#include <QBoxLayout>
#include <QPushButton>
#include <QStatusBar>


CToDoList::CToDoList(QWidget *parent)
    : QMainWindow(parent)
{

    move(411, 200);

    QWidget * allWindow = new QWidget(this);
    allWindow->setStyleSheet("background-color: AntiqueWhite");
    setCentralWidget(allWindow);

    QLabel * lblTitle = new QLabel("To Do List", this);
    lblTitle->setStyleSheet("font-size: 37px;");
    lblTitle->setAlignment(Qt::AlignCenter);

    QLabel * lPending = new QLabel("pending", this);
    lPending->setStyleSheet("font-size: 20px; font: bold;");

    QLabel * lCompleted = new QLabel("Completed", this);
    lCompleted->setStyleSheet("font-size: 20px; font: bold;");


//**********************************Button*****************************//

    dreamButton = new QPushButton("Motivation button");
    connect(dreamButton, SIGNAL(clicked()),
 this, SLOT(onDreamButtonPressed()));


//**********************************QListView**************************//
    leftList = new QListView(this);
    leftList-> setDragEnabled(true);   //take a line
    leftList-> setAcceptDrops(true); // line from right to left
    leftList->setDefaultDropAction(Qt::MoveAction);

    rightList = new QListView(this);
    rightList-> setDragEnabled(true);
    rightList-> setAcceptDrops(true);
    rightList->setDefaultDropAction(Qt::MoveAction);


//************************(leftList,rightList) ListViews styles********//


     leftList->setStyleSheet(
                 "QListView {font-size: 25px; font: italic;}"
                 "QListView::item {background-color: tomato;"
                 "border: 1px solid black;}"
                 "QListView::item::hover {background-color: grey}"
                         );

     rightList->setStyleSheet(
                   "QListView {font-size: 25px; font: italic;}"
                   "QListView::item {background-color: #2ECC71;"
                   "border: 1px solid black;}"
                   "QListView::item::hover {background-color: grey}"
                              );

        leftList->setModel(new QStringListModel());
        rightList->setModel(new QStringListModel());



//**********************************Layouts****************************//


    QVBoxLayout * lyt = new QVBoxLayout();
    QHBoxLayout * hlyt = new QHBoxLayout();
    QHBoxLayout * listLayout = new QHBoxLayout();

    lyt->addWidget(lblTitle);
    hlyt->addWidget(lPending);
    hlyt->addWidget(lCompleted);
    lyt->addWidget(dreamButton);

    listLayout->addWidget(leftList);
    listLayout->addWidget(rightList);

    allWindow->setLayout(lyt);
    lyt->addLayout(hlyt);
    lyt->addLayout(listLayout);


//**********************************QAction (icons)********************//


     QToolBar * pToolBar = new QToolBar(this);
     addToolBar(pToolBar);

     add = new QAction(this);
     remove = new QAction(this);

     add->setIcon(QIcon(":/icon/add.png"));
     remove->setIcon(QIcon(":/icon/delete.png"));

     connect(add, SIGNAL(triggered()), this, SLOT(onAddPressed()));
     connect(remove, &QAction::triggered,
 this, &CToDoList::onRemovePressed); //right


     pToolBar->addAction(add);
     pToolBar->addAction(remove);
}

//**********************************Functions**************************//


     void CToDoList::onAddPressed()
     {
        leftList->model()->insertRow(leftList->model()->rowCount());
        QModelIndex Getindex = leftList->model()->index(leftList->
model()->rowCount() -1,0);
        leftList->edit(Getindex);
     }

     void CToDoList::onRemovePressed()
     {
        QModelIndex yntacikTox = leftList->currentIndex();
        leftList->model()->removeRow(yntacikTox.row());
     }

      void CToDoList::onDreamButtonPressed()
     {
         statusBar()->showMessage(" Believe in yourself!", 2000);
     }



5. Resources - images.qrc - /icon



















Result:











Login Password Project

Login Password project (Gui Programming) 1. LoginPassword.pro QT += core gui greaterThan ( QT_MAJOR_VERSION , 4): QT += widge...