Qt 技巧:去除对话框边框 + 设置窗口可移动和透明

来源:互联网 发布:南京大学软件学院地址 编辑:程序博客网 时间:2024/05/17 09:22
1、去除对话框标题栏和边框
在构造函数里设置:
    this->setWindowFlags(Qt::FramelessWindowHint);

Qt::Dialog     (按照对话框的形式创建窗口--帮助/关闭)
Qt::Window  (按照正常窗口的形式创建窗口--最大化/最小化/关闭)

2、窗口可移动
去除边框会造成窗口不可移动,可以通过以下方法来解决:
自定义鼠标按下事件和鼠标移动事件:
void yourwindow::mousePressEvent(QMouseEvent *event)
{
     this->windowPos = this->pos();                // 获得部件当前位置
     this->mousePos = event->globalPos();     // 获得鼠标位置
     this->dPos = mousePos - windowPos;       // 移动后部件所在的位置
}

void yourwindow::mouseMoveEvent(QMouseEvent *event)
{
     this->move(event->globalPos() - this->dPos);
}

3、设置窗口透明
在构造函数中添加:
    this->setAttribute(Qt::WA_TranslucentBackground);

<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(20) | 评论(0) | 转发(0) |
1

上一篇:Qt 技巧:设置在 debug 路径下直接运行可执行文件

下一篇:Qt 代码: QComboBox 添加图片

相关热门文章
  • test123
  • 编写安全代码——小心有符号数...
  • 使用openssl api进行加密解密...
  • 一段自己打印自己的c程序...
  • sql relay的c++接口
给主人留下些什么吧!~~
评论热议
0 0