QQ基本功能实现 C语言 QT

头文件

#define WIDGET_H

#include <QWidget>

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

private slots:
    void on_toolButton_4_clicked();

    void on_pushButton_clicked();

    void on_toolButton_6_clicked();

    void on_pushButton_2_clicked();
    void suoxiao();





    void on_toolButton_8_clicked();

private:
    Ui::Widget *ui;
    QPoint mousePoint;


protected://受保护部分
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);


}
;
#endif // WIDGET_H
#include "widget.h"
#include <QApplication>

## main.cpp文件

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

    return a.exec();
}
## widget.cpp文件
#include "widget.h"
#include "ui_widget.h"
#include <QMovie>
#include <qpainter.h>
#include <QDialog>
#include<QFile>
#include<QShowEvent>
#include<QMouseEvent>
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    //ui->label->setPixmap(QString(":/QQ登录界面图片资源/back.gif"));//图片显示
    QMovie *movie =new QMovie();
    movie->setFileName(":/QQ登录界面图片资源/back.gif");
    ui->label->setMovie(movie);
   // ui->label_2->setPixmap(QString(":/QQ登录界面图片资源/HeadImage.png"));
    movie->start();
   /* QPalette pal =palette();
    pal.setColor(QPalette::Background,QColor(255,255,255,0));
    this->setPalette(pal);
    this->setAttribute(Qt::WA_TranslucentBackground,true);*/
    this->setWindowFlags(Qt::FramelessWindowHint);
    //this->setWindowOpacity(0.0);
   // ui->widget->hide();
    //ui->toolButton_4->setStyleSheet("QToolButton:hover{background-color: rgb(255, 85, 0);}");
    QFile css(":/1.qss");
    css.open(QFile::ReadOnly);
    ui->toolButton_4->setStyleSheet(css.readAll());
    css.close();
    connect(ui->toolButton_4,SIGNAL(clicked()),this,SLOT(suoxiao()));

}

Widget::~Widget()
{
    delete ui;
}
/*void Widget::paintEvent(QPaintEvent *e)
{
    QPainter p(this);
    p.fillRect(this->rect(),QColor(0,0,255,0));



}*/

void Widget::on_toolButton_4_clicked()
{
    close();
}

void Widget::on_pushButton_clicked()
{
   QDialog *d =new QDialog;
   d->show();
}

void Widget::on_toolButton_6_clicked()
{
    QDialog *f =new QDialog;
    f->show();
}

void Widget::on_pushButton_2_clicked()
{
    QDialog *m =new QDialog;
    m->show();


}

void Widget::on_toolButton_8_clicked()
{

}
void Widget::mousePressEvent(QMouseEvent *e)
{
   // QDialog *d =new QDialog;
    //d->show(); 生成新的对话框
   // ui->pushButton->setText(QString("%1,%2").arg(e->x()).arg(e->y()));
   if(e->button() ==Qt::LeftButton)
    {
        mousePoint = e->globalPos() -this->pos();
        e->accept();
    }
}
void Widget::mouseMoveEvent(QMouseEvent *e)
{
   if(e->buttons() && Qt::LeftButton) {


       this->move(e->globalPos()-mousePoint);
       e->accept();
   }

}
void Widget::suoxiao()
{
    this->hide();
}
![界面文件](https://img-blog.csdnimg.cn/20190425181243970.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDgzMzIwMQ==,size_16,color_FFFFFF,t_70)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值