欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > qt-17不规则窗体

qt-17不规则窗体

2024/10/24 15:19:49 来源:https://blog.csdn.net/weixin_41725706/article/details/141336111  浏览:    关键词:qt-17不规则窗体

不规则窗体

  • 知识点
  • shape.h
  • shape.cpp
  • main.cpp
  • 运行图

知识点

感觉这个就是在图片背景 贴了白色

shape.h

#ifndef SHAPE_H
#define SHAPE_H#include <QWidget>class Shape : public QWidget
{Q_OBJECTpublic:Shape(QWidget *parent = nullptr);~Shape();
protected:void mousePressEvent(QMouseEvent*);void mouseMoveEvent(QMouseEvent *event);void paintEvent(QPaintEvent*);
private:QPoint DragPosition;};
#endif // SHAPE_H

shape.cpp

#include "shape.h"
#include <QMouseEvent>
#include <QPainter>
#include <QPixmap>
#include <QBitmap>Shape::Shape(QWidget *parent): QWidget(parent)
{QPixmap Pix;Pix.load("312.ico",0,Qt::AvoidDither|Qt::ThresholdDither|Qt::ThresholdAlphaDither);resize(Pix.size());setMask(QBitmap(Pix.mask()));}Shape::~Shape() {}void Shape::mousePressEvent(QMouseEvent *Event)
{if(Event->button() == Qt::LeftButton){DragPosition = Event->globalPos() - frameGeometry().topLeft();Event->accept();}if(Event->button() == Qt::RightButton){close();}}void Shape::mouseMoveEvent(QMouseEvent *Event)
{if(Event->buttons()&Qt::LeftButton){move(Event->globalPos()-DragPosition);Event->accept();}
}void Shape::paintEvent(QPaintEvent*)
{QPainter Painter(this);Painter.drawPixmap(0,0,QPixmap("312.ico"));}

main.cpp

#include "shape.h"#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);Shape w;w.show();return a.exec();
}

运行图

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com