zoukankan      html  css  js  c++  java
  • Qt 无边框

    #ifndef FRAMELESSWINDOW_H
    #define FRAMELESSWINDOW_H
    
    #include <QtGui/QWidget>
    #include "ui_framelesswindow.h"
    
    class QMouseEvent;
    
    class framelessWindow : public QWidget
    {
    	Q_OBJECT
    
    public:
    	framelessWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
    	~framelessWindow();
    
    private:
    	Ui::framelessWindowClass ui;
    
    	void mousePressEvent(QMouseEvent *event) override;
    	void mouseMoveEvent(QMouseEvent *event) override;
    	void mouseReleaseEvent(QMouseEvent *event) override;
    
    	bool mIsPressed;
    	QPoint mVectorDiff;
    };
    
    #endif // FRAMELESSWINDOW_H
    
    
    #include "framelesswindow.h"
    #include <QMouseEvent>
    
    framelessWindow::framelessWindow(QWidget *parent, Qt::WFlags flags)
    	: QWidget(parent, flags)
    	, mIsPressed(false)
    {
    	ui.setupUi(this);
    	setWindowFlags(Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);
    }
    
    framelessWindow::~framelessWindow()
    {
    
    }
    
    void framelessWindow::mousePressEvent(QMouseEvent *event)
    {
    
    	mIsPressed = true;
    
    	// event->globalPos():向量,从屏幕左上到鼠标
    	// this->pos():向量,从屏幕左上到程序左上
    	// mVectorDiff:向量差
    	mVectorDiff = event->globalPos() - this->pos();
    
    }
    
    void framelessWindow::mouseMoveEvent(QMouseEvent *event)
    {
    	if (mIsPressed)
    	{
    		// 鼠标在程序中的坐标不变,即向量差不变
    		QPoint targetPoint = event->globalPos() - mVectorDiff;
    		move(targetPoint);
    	}
    }
    
    void framelessWindow::mouseReleaseEvent(QMouseEvent *event)
    {
    	mIsPressed = false;
    }
    
  • 相关阅读:
    php责任链模式
    php工厂模式
    php观察者模式
    php单例模式
    php的抽象类
    Mysqli的常用函数
    PDO的基本操作
    算法--各种算法
    file_get_post实现post请求
    redis的5种数据结构的使用场景介绍
  • 原文地址:https://www.cnblogs.com/kohlrabi/p/7117949.html
Copyright © 2011-2022 走看看