zoukankan      html  css  js  c++  java
  • qt 界面去掉系统边框

    该代码在Qt5框架编辑,使用该类时, 直接继承这个类就可以了。 实现了拖拽功能和关闭功能,如果需要放大缩小功能, 需自己实现。

    1
    #ifndef CUSTOMIZE_QWIDGET_H 2 #define CUSTOMIZE_QWIDGET_H 3 #include <QWidget> 4 #include <QMouseEvent> 5 6 class CustomizeQWidget : public QWidget 7 { 8 Q_OBJECT 9 public: 10 explicit CustomizeQWidget(QWidget *parent = 0); 11 ~CustomizeQWidget(); 12 public slots: 13 void on_button_close_clicked(); 14 private: 15 void paintEvent(QPaintEvent *); 16 void mousePressEvent(QMouseEvent *event); 17 void mouseMoveEvent(QMouseEvent *event); 18 private: 19 QPoint m_last_mouse_position; 20 }; 21 #endif // CUSTOMIZE_QWIDGET_H
     1 #include "customize_qwidget.h"
     2 #include <QStyleOption>
     3 #include <QPainter>
     4 #include <QBrush>
     5 
     6 CustomizeQWidget::CustomizeQWidget(QWidget *parent)
     7     : QWidget(parent)
     8 {
     9     this -> setWindowFlags(Qt::FramelessWindowHint);
    10 }
    11 
    12 CustomizeQWidget::~CustomizeQWidget()
    13 {
    14 }
    15 
    16 void CustomizeQWidget::paintEvent(QPaintEvent *)
    17 {
    18     QStyleOption opt;
    19     opt.init(this);
    20     QPainter p(this);
    21     style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    22 }
    23 
    24 void CustomizeQWidget::mousePressEvent(QMouseEvent *event)
    25 {
    26     if(event->button() == Qt::LeftButton)
    27     {
    28         m_last_mouse_position = event->globalPos();
    29     }
    30 }
    31 
    32 void CustomizeQWidget::mouseMoveEvent(QMouseEvent *event)
    33 {
    34     if (!event->buttons().testFlag(Qt::LeftButton))
    35             return;
    36     const QPoint position = pos() + event->globalPos() - m_last_mouse_position; //the position of mainfrmae + (current_mouse_position - last_mouse_position)
    37     move(position.x(), position.y());
    38     m_last_mouse_position = event->globalPos();
    39 }
    40 
    41 void CustomizeQWidget::on_button_close_clicked()
    42 {
    43     this->close();
    44 }
  • 相关阅读:
    git常用操作命令
    如何编写高质量代码
    Chrome调试工具简单介绍
    使用eclipse+tomcat搭建本地环境
    chrome设置--disable-web-security解决跨域
    利用Maven管理工程项目本地启动报错及解决方案
    用户输入验证【提升篇】
    简单【用户输入验证】
    【消息框】的返回值
    【消息框】的4种显示形式
  • 原文地址:https://www.cnblogs.com/devil-shadow/p/11725622.html
Copyright © 2011-2022 走看看