欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 建筑 > QT day3

QT day3

2025/4/19 18:26:37 来源:https://blog.csdn.net/Artorias_Ch/article/details/142069377  浏览:    关键词:QT day3

代码

#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include <QLabel>
#include <QIcon>
#include <QPixmap>
#include<QLineEdit>
#include<QCheckBox>
#include <QPushButton>
#include <QFrame>
#include<QMessageBox>
#include<QTextEdit>
#include <QColor>
#include<QColorDialog>class MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();private:QLabel *lb1;QLabel *lb2;QLabel *lb3;QLabel *lb4;QLineEdit *le1;QLineEdit *le2;QCheckBox *cb1;QCheckBox *cb2;QPushButton *btn1;QPushButton *btn2;QPushButton *btn3;QPushButton *btn4;QFrame *frame;QTextEdit *te;QPushButton *btn5;};
#endif // MAINWINDOW_H
#include "mainwindow.h"MainWindow::MainWindow(QWidget *parent): QMainWindow(parent)
{this->resize(430,330);this->move(this->x()+750,this->y()+350);this->setWindowIcon(QIcon("://icon/1.png"));this->setFixedSize(430,330);this->setWindowTitle("QQ");this->lb1 = new QLabel(this);this->lb2 = new QLabel(this);this->lb3 = new QLabel(this);lb1->resize(430,130);lb1->setScaledContents(true);lb1->setPixmap(QPixmap("://icon/2.png"));this->le1 = new QLineEdit(this);this->le2 = new QLineEdit(this);le1->move(100,150);    //移动位置le1->resize(250,30);le2->move(100,le1->y()+le1->height()+10);lb2->resize(25,30);lb3->resize(25,30);lb2->setScaledContents(true);lb3->setScaledContents(true);lb2->move(70,150);lb3->move(70,190);lb3->setPixmap(QPixmap("://icon/3.jpg"));lb2->setPixmap(QPixmap("://icon/1.png"));le2->resize(250,30);le2->setEchoMode(QLineEdit::Password);this->cb1 =new QCheckBox(this);this->cb2 =new QCheckBox(this);cb1->setText("自动登录");cb2->setText("记住密码");cb1->move(77,230);cb2->move(150,230);this->btn1 = new QPushButton("注册账号",this);this->btn2 = new QPushButton("登录",this);this->btn3 = new QPushButton("找回密码",this);btn3->move(250,230);btn1->resize(70,30);btn2->resize(140,30);btn2->move(77,270);btn2->setStyleSheet("background-color:skyblue; border-radius:3;");btn3->setStyleSheet("QPushButton { background-color: rgba(255, 255, 255,0); }");btn1->move(7,300);btn1->setStyleSheet("QPushButton { background-color: rgba(255, 255, 255,0); }");this-> lb4= new QLabel(this);lb4->setPixmap(QPixmap("://icon/3.png"));lb4->move(390,295);lb4->setStyleSheet("QPushButton { background-color: rgba(255, 255, 255,0); }");this->btn4 = new QPushButton("关闭",this);btn4->resize(140,30);btn4->move(220,270);btn4->setStyleSheet("background-color:skyblue; border-radius:3;");this->frame=new QFrame(this);frame->resize(430,330);frame->close();this->te=new QTextEdit(frame);te->resize(430,200);frame->setStyleSheet("background-color:rgba(27,233,199,255);");this->btn5 = new QPushButton("颜色",frame);btn5->resize(140,30);btn5->move(220,270);//btn2登录  btn4取消connect(this->btn2,&QPushButton::clicked,[&](){if(le1->text()==le2->text()){QMessageBox box( QMessageBox::Information,//图标"登录信息",          //对话框标题"登录成功!!!",             //对话框内容QMessageBox::Ok, //提供的按钮this); //父组件)int res= box.exec();if(res ==QMessageBox::Ok){frame->show();}}else{QMessageBox box(QMessageBox::Warning,"登录信息","账号或密码错误",QMessageBox::Yes|QMessageBox::No,this );int res=box.exec();if(res==QMessageBox::Yes){le1->clear();le2->clear();}else if(res==QMessageBox::No){close();}}});connect(this->btn4,&QPushButton::clicked,[&](){int res= QMessageBox::question(this,"请问","是否关闭QQ",QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes);if(res == QMessageBox::Yes){close();}});connect(this->btn5,&QPushButton::clicked,[&](){QColor c= QColorDialog::getColor("white",frame,"请选择颜色");\if(c.isValid()){//表示用户选中了颜色//将当前选中的颜色,放到文本编辑器上//this->te->setTextColor(c);        //设置字体 前景色this->te->setTextBackgroundColor(c);      //设置字体背景色}else{//表示用户没有选择颜色QMessageBox::information(this,"提示","您没有选择颜色");}});}MainWindow::~MainWindow()
{
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词