1.
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
this->resize(540,415);
this->setFixedSize(540,415);
//窗口标题
this->setWindowTitle("盗版QQ");
//窗口图标
this->setWindowIcon(QIcon("E:\\qq\\pictrue\\pictrue\\qq.png"));
//背景颜色
this->setStyleSheet("background-color:white");
//============标签相关设置=======
QLabel *lab1 = new QLabel(this);
//设置大小
lab1->resize(540, 160);
lab1->setStyleSheet("background-color:pink");
//动图类 接收动图
QMovie *mv = new QMovie("E:\\qq\\pictrue\\pictrue\\zz.gif");
//将动图放入标签中
lab1->setMovie(mv);
//让动图动起来
mv->start();
//自动适应
lab1->setScaledContents(true);
QLabel *lab2 = new QLabel(this);
lab2->resize(30,30);
lab2->move(120,210);
lab2->setPixmap(QPixmap("E:\\qq\\pictrue\\pictrue\\wodepeizhenshi.png"));
lab2->setScaledContents(true);
QLabel *lab3 = new QLabel(this);
lab3->resize(30,30);
lab3->move(120, 260);
lab3->setPixmap(QPixmap("E:\\qq\\pictrue\\pictrue\\passwd.jpg"));
lab3->setScaledContents(true);
//============行编辑器相关设置=======
edit3 = new QLineEdit(this);
edit3->resize(275,30);
edit3->move(155,210);
edit3->setPlaceholderText("QQ号/手机号/邮箱");
edit2 = new QLineEdit(this);
edit2->resize(275,30);
edit2->move(155,260);
edit2->setPlaceholderText("密码");
edit2->setEchoMode(QLineEdit::Password);
//============按钮相关设置=======
QPushButton *btn = new QPushButton("登录",this);
btn->resize(300,45);
btn->move(120,345);
connect(btn,&QPushButton::clicked,this,&Widget::btn1_clicked);
}
void Widget::btn1_clicked()
{
if(this->edit3->text() == "Admin" && this->edit2->text() == "123456")
{
QMessageBox box(QMessageBox::Question,
"信息对话框",
"登录成功",
QMessageBox::Ok,
this);
int res1 = box.exec();
if(res1 == QMessageBox::Ok)
{
emit jump();
this->close();
}
}else
{
QMessageBox box(QMessageBox::Critical,
"错误对话框",
"登录失败,是否重新登录",
QMessageBox::Ok|QMessageBox::No,
this);
// box.setButtonText(QMessageBox::Ok,"yes");
// box.setButtonText(QMessageBox::No,"no");
int res = box.exec();
if(res == QMessageBox::Ok)
{
this->edit2->clear();
this->edit3->clear();
}else if(res == QMessageBox::No)
{
this->close();
}
}
}
Widget::~Widget()
{
}
2.
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_pushButton_clicked()
{
bool ok = false;
QFont f = QFontDialog::getFont(&ok,
QFont("宋体",10,10,true),
this,
"选择字体");
if(ok)
{
ui->textEdit->setCurrentFont(f);
}
}
void Widget::on_pushButton_2_clicked()
{
QColor c = QColorDialog::getColor(QColor("red"),
this,
"选择颜色");
if(c.isValid() == true)
{
ui->textEdit->setTextColor(c);
}
}
void Widget::on_pushButton_3_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this,
"选择文件",
"./",
"all(*.*);;images(*.png *.jpg *.gif);;源文件(*.cpp)");
qDebug() << fileName;
QFile file(fileName);
if(file.open(QFile::ReadOnly) == false)
{
QMessageBox::information(this,"提示","文件打开失败");
return;
}
QByteArray msg = file.readAll();
ui->textEdit->setText(msg);
file.close();
}
void Widget::on_pushButton_4_clicked()
{
QString fileName = QFileDialog::getSaveFileName(this,
"选择文件",
"./",
"all(*.*);;images(*.png *.jpg *.gif);;源文件(*.cpp)");
QFile file(fileName);
//打开文件
if(!file.open(QFile::WriteOnly))
{
return;
}
//获取textEdit中的内容
QString msg = ui->textEdit->toPlainText();
//将textEdit中的内容写入到filename中
file.write(msg.toLocal8Bit());
//关闭文件
file.close();
}