Qt
1>将文本编辑器完整实现
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);this->resize(800,600);edit1 = new QTextEdit(this);edit1->resize(600,600);//字体btnziti = new QPushButton("字体",this);btnziti->resize(150,50);btnziti->move(625,50);//颜色btncolor = new QPushButton("颜色",this);btncolor->resize(150,50);btncolor->move(625,125);//打开文件btnopen = new QPushButton("打开文件",this);btnopen->resize(150,50);btnopen->move(625,200);//保存文件btnsave = new QPushButton("保存文件",this);btnsave->resize(150,50);btnsave->move(625,275);connect(btnziti,&QPushButton::clicked,[=](){bool ok = false;QFont f = QFontDialog::getFont(&ok,QFont("宋体",10,10,true),this,"选择字体");if(ok){edit1->setCurrentFont(f);}});connect(btncolor,&QPushButton::clicked,[=](){QColor c = QColorDialog::getColor(QColor("red"),this,"选择颜色");if(c.isValid() == true){edit1->setTextBackgroundColor(c);}});connect(btnopen,&QPushButton::clicked,this,&Widget::openfile);connect(btnsave,&QPushButton::clicked,this,&Widget::savefile);
}Widget::~Widget()
{delete ui;
}void Widget::openfile()
{QString filename = QFileDialog::getOpenFileName(this,"选择文件","./","all(*.*)");QFile file(filename);if(file.open(QFile::ReadOnly)==false){QMessageBox::information(this,"提示","文件打开失败");return;}QByteArray msg = file.readAll();edit1->setText(msg);file.close();
}void Widget::savefile()
{QString filename = QFileDialog::getOpenFileName(this,"选择文件","./","all(*.*)");QFile file(filename);if(file.open(QFile::WriteOnly)==false){QMessageBox::information(this,"提示","文件打开失败");return;}QString msg = edit1->toPlainText();file.write(msg.toUtf8().data());file.close();
}
2>重新将登录框实现完整
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent)
{//=======窗口相关设置======this->resize(680,520);this->setFixedSize(680,520);this->setWindowTitle("Tim");this->setWindowFlag(Qt::FramelessWindowHint);this->setStyleSheet("background-color:rgb(255,255,255)");//=======标签相关设置======QLabel *lab1 = new QLabel(this);lab1->resize(400,520);lab1->setPixmap(QPixmap(":/pictrue/tim.png"));//=======行编辑器相关设置=======edit1 = new QLineEdit(this);edit1->resize(220,50);edit1->move(430,270-50);edit1->setPlaceholderText("QQ号码/手机号/邮箱");edit2 = new QLineEdit(this);edit2->resize(220,50);edit2->move(430,270);edit2->setPlaceholderText("密码");edit2->setEchoMode(QLineEdit::Password);//=======按钮相关设置=====QPushButton *btn1 = new QPushButton(this);btn1->resize(64,64);btn1->move(500-32,120-32);btn1->setStyleSheet("background-color:rgb(17,145,255);border-radius:32px");btn1->setIcon(QIcon(":\\pictrue\\qie.png"));QPushButton *btn2 = new QPushButton(this);btn2->resize(64,64);btn2->move(580-32,120-32);btn2->setStyleSheet("background-color:rgb(245,245,245);border-radius:32px");btn2->setIcon(QIcon(":\\pictrue\\wechat.png"));QPushButton *btn3 = new QPushButton("记住密码",this);btn3->resize(74,25);btn3->move(430,440);btn3->setIcon(QIcon(":\\pictrue\\kuang.png"));QPushButton *btn4 = new QPushButton("自动登陆",this);btn4->resize(74,25);btn4->move(430,470);btn4->setIcon(QIcon(":\\pictrue\\kuang.png"));QPushButton *btn5 = new QPushButton("找回密码",this);btn5->resize(74,25);btn5->move(600,440);QPushButton *btn6 = new QPushButton("注册密码",this);btn6->resize(74,25);btn6->move(600,470);btn7 = new QPushButton(this);btn7->resize(25,25);btn7->move(640,12);btn7->setIcon(QIcon(":\\pictrue\\x.png"));QPushButton *btn8 = new QPushButton(this);btn8->resize(25,25);btn8->move(605,12);btn8->setIcon(QIcon(":\\pictrue\\set.png"));btn9 = new QPushButton("登录",this);btn9->resize(220,50);btn9->move(430,270+80);// btn9->setStyleSheet("background-color:red;border-radius:5px");connect(edit1, &QLineEdit::textChanged, this, &Widget::mySlots);connect(edit2, &QLineEdit::textChanged, this, &Widget::mySlots);connect(btn7, &QPushButton::clicked, this, &Widget::clicked);connect(btn9, &QPushButton::clicked, [&](){if(edit1->text()=="123456"&&edit2->text()=="123456"){int res = QMessageBox::information(this,"登录","登录成功",QMessageBox::Ok,QMessageBox::Ok);if(res == QMessageBox::Ok){emit jump();this->close();}
// qDebug() << "denglu" ;
// emit jump();
// this->close();}else{QMessageBox box(QMessageBox::Critical,"问题","登录失败,是否重新登录",QMessageBox::Ok|QMessageBox::No,this);box.setButtonText(QMessageBox::No,"no");box.setButtonText(QMessageBox::Ok,"yes");int res = box.exec();if(res == QMessageBox::Ok){edit1->clear();edit2->clear();}else if(res == QMessageBox::No){this->close();}}});
}
Widget::~Widget()
{delete ui;
}
void Widget::clicked()
{QMessageBox box(QMessageBox::Question,"问题","您是否确认退出登录",QMessageBox::Ok|QMessageBox::No,this);box.setButtonText(QMessageBox::No,"no");box.setButtonText(QMessageBox::Ok,"yes");int res = box.exec();if(res == QMessageBox::Ok){this->close();}else if(res == QMessageBox::No){}}
void Widget::mySlots()
{if(edit1->text().size()>=6&&edit2->text().size()>=6){btn9->setEnabled(true);
// btn9->setStyleSheet("background-color:green;border-radius:5px");}else{btn9->setEnabled(false);
// btn9->setStyleSheet("background-color:red;border-radius:5px");}
}
#include "second.h"
#include "ui_second.h"void Second::fun()
{this->show();
}Second::Second(QWidget *parent) :QWidget(parent),ui(new Ui::Second)
{ui->setupUi(this);
}Second::~Second()
{delete ui;
}