嵌入式下Qt背景隐藏

来源:互联网 发布:伯明翰大学 知乎 编辑:程序博客网 时间:2024/06/05 04:08

嵌入式平台,我们使用的QT会是以QWS方式运行,即会先运行QWSServer,再运行实际的窗体,在该情况下,默认QWS背景会是绿色的。

如果qt程序需要设置背景透明,共需要设置两处:一处是QWS,一处是窗体。

  • 设置QWS透明(鼠标不可见)
QWSServer::setBackground(QColor(0,0,0,0));QWSServer::setCursorVisible(false);
  • 设置窗口透明(包括无边框)
w.setWindowOpacity(1);    w.setWindowFlags(Qt::FramelessWindowHint);    w.setAttribute(Qt::WA_TranslucentBackground);

对窗体无边框的设置要写在main里面,这样所有派生的子窗口,QDialog,QWidget都可继承, 很好规划和管理,方便统一美化设计。

可能会产生一个问题:窗口无法移动。
这也是无边框导致的,可以在在每个子窗口中,都添加:

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