Search code examples
qtuser-interfacetransparencyembedded-linuxqwidget

Embedded Qt GUI Artifacts Appear when Dismissing Widgets


I am working on a touchscreen GUI for an embedded Linux device that will sit over a video feed. Therefore, I need my GUI to be transparent and disappear after some timeout so the user can just view the video feed. The main.cpp of my GUI ensures that the background of the entire application running with the -qws option is transparent with the following code:

QApplication a(argc, argv, QApplication::GuiServer);
QWSServer::instance()->setBackground(QBrush(Qt::NoBrush));
QWSServer::setCursorVisible (false);

I have a main, bottom level widget that owns every other widget in the GUI. I set the background to transparent with the following pallete related code.

QPalette transparentPallete;
transparentPallete.setColor(QPalette::Window, Qt::transparent);
setAutoFillBackground(true);
setPalette(transparentPallete);

I also overrode the paintEvent method to try to ensure that the background would always be in a clean transparent state:

void MainWidget::paintEvent(QPaintEvent *event)
{
    QPainter p(this);

    // Fill background
    p.setPen(Qt::NoPen); // no outlines
    p.fillRect(0,0,width(),height(),QColor(255, 255, 255, 0)); // Fill rectangle with color

}

Now I can launch my application and view my GUI over the raw video feed and I can interact by touch to bring up different windows within the GUI and have them disappear.

What I cannot accomplish is to get rid of artifacts that are left behind when I hit 'cancel' or order certain portions of the GUI to disappear. These artifacts look really ugly ( multiple vertical lines / wrong colors ) and only disappear when another part of the GUI is summoned that replaces that location on the screen. They are there regardless of whether I have the video feed enabled ( which lives on a different overlay controlled by the processor dss anyway ).

How can I get rid of these artifacts that are left behind after dismissing some widgets?

NOTE: This definetly is correlated with the following line:

QWSServer::instance()->setBackground(QBrush(Qt::NoBrush)); // Allows transparent pixels to be written to frame buffer

If I turn this line off, I cannot see the underlying overlay but I also do not get any strange behavior whatsoever and my performance becomes much better. How can I achieve transparency but also lose the strange artifacts?


Solution

  • Well the following has an issue apparently:

    QWSServer::instance()->setBackground(QBrush(Qt::NoBrush));
    

    But this solves the problem and I see 0 artifacts:

    QWSServer::setBackground(QBrush(QColor(0, 0, 0, 0)));