1> 繼續(xù)完善登錄框,當(dāng)?shù)卿洺晒r(shí),關(guān)閉登錄界面,跳轉(zhuǎn)到新的界面中
widget.h
#include "widget.h" //#include "ui_widget.h" Widget::Widget(QWidget *parent) : QWidget(parent) //, ui(new Ui::Widget) { //ui->setupUi(this); this->setFixedSize(800,650); //設(shè)置固定尺寸 qDebug()<<this->windowTitle(); //獲取窗口標(biāo)題 this->setWindowTitle("英雄去超越"); this->setWindowOpacity(0.9); //5.設(shè)置窗口圖標(biāo) this->setWindowIcon(QIcon(":/icon/yxlm.png")); //設(shè)置大圖 lab1 = new QLabel(this); lab1->resize(800,380); lab1->setPixmap(QPixmap(":/icon/logo.png")); lab1->setScaledContents(true); //使用無參構(gòu)造函數(shù),構(gòu)造出一個(gè)按鈕 btn1 = new QPushButton; btn1->setParent(this); //將當(dāng)前界面設(shè)置成父組件 btn1->setText("登錄"); //設(shè)置按鈕上的文本內(nèi)容 btn1->resize(80,40); //重新設(shè)置組件的大小 btn1->move(500,550); //移動(dòng)組件 btn1->setStyleSheet("background-color:cyan;");//設(shè)置樣式表 btn1->setIcon(QIcon(":/icon/2.png")); btn2 = new QPushButton(this); btn2->setText("取消"); //設(shè)置按鈕上的文本內(nèi)容 btn2->resize(80,40); //重新設(shè)置組件的大小 btn2->move(600,550); //移動(dòng)組件 btn2->setStyleSheet("background-color:skyblue;");//設(shè)置樣式表 btn2->setIcon(QIcon(":/icon/1.png")); edit1 = new QLineEdit; edit1->setParent(this); edit1->resize(300,40); edit1-> move(250,450); edit1->setEchoMode((QLineEdit::Password)); edit1->setPlaceholderText("密碼"); edit2 = new QLineEdit(this); edit2->resize(300,40); edit2-> move(250,400); edit2->setPlaceholderText("賬號(hào)"); lab2 = new QLabel; lab2->setParent(this); lab2->setText("賬號(hào)"); lab2->resize(50,50); lab2->move(200,400); lab3 = new QLabel(this); lab3->setText("密碼"); lab3->resize(50,50); lab3->move(200,450); connect(btn1,SIGNAL(clicked()),this,SLOT(btn1_slot())); //qt5 connect(btn2,&QPushButton::clicked,this,&Widget::btn2_slot); //將自定義的信號(hào)與槽函數(shù)進(jìn)行連接 connect(this,&Widget::my_signal,[&](){ qDebug()<<"我已經(jīng)成功連接取消按鈕"; btn2->resize(btn2->width()+1,btn2->height()+1); }); //將同一個(gè)信號(hào)連接到同一個(gè)槽 //connect(this,&Widget::my_signal,this,&Widget::close); } Widget::~Widget() { delete ui; } void Widget::my_slot() { this->close(); } void Widget::btn1_slot() { QString userName = edit2->text(); QString pwd = edit1->text(); if(userName == "admin" && pwd == "123456" ) { qDebug()<<"登錄成功"; this->close(); emit jump(); this->close(); }else { qDebug()<<"登錄失敗,請(qǐng)重新登錄"; edit1->clear(); } } void Widget::btn2_slot() { static int num = 0; qDebug()<<++num; //發(fā)射自定義的信號(hào) emit my_signal(); }
2> 新建一個(gè)工程文件,將默認(rèn)提供的代碼加上注釋信息
工程管理文件.pro
QT += core gui #表示引入qt所需的類庫,如核心庫、圖形化界面庫 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets #如果超過4.0版本,系統(tǒng)會(huì)自動(dòng)加上widgets庫 CONFIG += c++11 #該版本的qt支持c++11后的語法 # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 #管理源文件 SOURCES += \ main.cpp \ widget.cpp #管理頭文件 HEADERS += \ widget.h #管理ui文件 FORMS += \ widget.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target
3> 思維導(dǎo)圖
文章來源:http://www.zghlxwxcb.cn/news/detail-610595.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-610595.html
到了這里,關(guān)于QT:當(dāng)?shù)卿洺晒r(shí),關(guān)閉登錄界面,跳轉(zhuǎn)到新的界面中的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!