1、设置窗口边框消失和窗口透明
Shape::Shape(QWidget *parent) :
QWidget(parent),
ui(new Ui::Shape)
{
ui->setupUi(this);
//去窗口边框
setWindowFlags(Qt::FramelessWindowHint | windowFlags());
//窗口背景设置为透明
setAttribute(Qt::WA_TranslucentBackground);
}
2、设置窗口移动
//按下
void Shape::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::RightButton)
{
close();
}else if(event->button() == Qt::LeftButton)
{
//求坐标差
//当前的点击坐标值减去左上角的
pd = event->globalPos() - this->frameGeometry().topLeft();
}
}
//移动
void Shape::mouseMoveEvent(QMouseEvent *event)
{
if(event->buttons() & Qt::LeftButton)
{
this->move(event->globalPos() - pd);
}
}