当前位置:网站首页>QT interface optimization: QT border removal and form rounding

QT interface optimization: QT border removal and form rounding

2022-04-23 14:27:00 Spiritual health

Qt Interface optimization :Qt Border removal and form rounding


One 、 design sketch

 Insert picture description here

Two 、 Use steps

1. .h part

The code is as follows :

#include <QMovie>
#include <QLabel>
#include <QMouseEvent>
#include <QLine>

// Form rounding 
#include <QBitmap>
#include <QPainter>
// The form can be dragged 
private:
    void mouseMoveEvent(QMouseEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    QPoint z;

private:
    void Beawidget(); // Window interface optimization  

2. .cpp part

The code is as follows :

Beawidget(); // Window interface optimization 
// The window can be moved 
void LoginWidget::mouseMoveEvent(QMouseEvent *event)
{
    
    QWidget::mouseMoveEvent(event);

    QPoint y =event->globalPos(); // The position of the mouse relative to the upper left corner of the desktop , Global mouse position 
    QPoint x =y-this->z;
    this->move(x);
}

void LoginWidget::mousePressEvent(QMouseEvent *event)
{
    
    QWidget::mousePressEvent(event);

    QPoint y =event->globalPos(); // The mouse is relative to the upper left corner of the desktop , Global mouse position 
    QPoint x =this->geometry().topLeft();   // The position of the upper left corner of the window relative to the desktop , window position 
    this-> z =y-x ;// Constant value 
}

void LoginWidget::mouseReleaseEvent(QMouseEvent *event)
{
    
    QWidget::mouseReleaseEvent(event);
    this->z=QPoint();
}

// Window interface optimization 
void LoginWidget::Beawidget()
{
    
    // Form border removal 
    this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint);
    this->setWindowTitle(" Yunxi Zhihua ");

    // Form rounding 
    QBitmap bmp(this->size());
    bmp.fill();

    QPainter p(&bmp);
    p.setPen(Qt::NoPen);
    p.setBrush(Qt::black);
    p.drawRoundedRect(bmp.rect(),20,20);

    setMask(bmp);
}


版权声明
本文为[Spiritual health]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231411423094.html