5

Qt界面优化:Qt去边框与窗体圆角化

 2 years ago
source link: https://blog.51cto.com/u_15745546/5688397
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Qt界面优化:Qt去边框与窗体圆角化

精选 原创

Qt界面优化:Qt去边框与窗体圆角化


一、效果图

Qt界面优化:Qt去边框与窗体圆角化_qt

二、使用步骤

1. .h部分

代码如下:

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

//窗体圆角化
#include <QBitmap>
#include <QPainter>
//窗体可拖动
private:
    void mouseMoveEvent(QMouseEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    QPoint z;

private:
    void Beawidget(); //窗口界面的优化    

2. .cpp部分

代码如下:

Beawidget(); //窗口界面优化
//窗口可移动
void LoginWidget::mouseMoveEvent(QMouseEvent *event)
{
    QWidget::mouseMoveEvent(event);

    QPoint y =event->globalPos(); //鼠标相对于桌面左上角的位置,鼠标全局位置
    QPoint x =y-this->z;
    this->move(x);
}

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

    QPoint y =event->globalPos(); //鼠标相对于桌面左上角,鼠标全局位置
    QPoint x =this->geometry().topLeft();   //窗口左上角相对于桌面位置,窗口位置
    this-> z =y-x ;//定值不变
}

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

//窗口界面优化
void LoginWidget::Beawidget()
{
    //窗体去边框
    this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint);
    this->setWindowTitle("云曦智划");

    //窗体圆角化
    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);
}


以上是部分Qt关于界面优化的部分,所有相关的Qt界面优化的部分,均在下方专栏——Qt界面优化中,大家如果感兴趣可以进行观看并使用,希望通过这些文章能够使大家的Qt软件更加美观和完美 !!!

另,如果大家有时间的话,也可以在个人主页中的专栏部分,查看我的Qt实战专栏Qt功能优化专栏哦,里面分别存放有Qt相关的实战软件和相对实用的附属功能,大家感兴趣可以看看(๑>؂<๑)

  • 收藏
  • 评论
  • 分享
  • 举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK