QQ基本功能实现 C语言 QT

头文件

#define WIDGET_H

#include 

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 

## 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 
#include 
#include 
#include
#include
#include
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)

你可能感兴趣的:(C/C语言,QT)