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

1720阅读 0评论2015-07-11 ygw982901730
分类:C/C++

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);

上一篇:Linux上使用gSOAP
下一篇:Qt SQL Programming 部分翻译