Question

I have created a Qt application which brings up a transparent widget. I have another Qt application already running which brings up a form. This Qt application will act as a parent for my transparent widget. After changing the parent of my transparent widget, when I move my parent Qt window, my transparent widget (now a child of the second Qt application), is not moving at all with respect to its parent.

Note: If I remove transparency code then my child widget follows its parent and move along with it.

This is my code:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{

    ui->setupUi(this);

    setWindowFlags(Qt::FramelessWindowHint);
    setStyleSheet("background:transparent;");
    setAttribute(Qt::WA_TranslucentBackground);

    this->setGeometry(200,200,500,500);


    WId hMSTSCWindow = NULL;

    //hMSTSCWindow = FindWindow(TEXT("TSSHELLWND"), NULL);
    hMSTSCWindow = FindWindow(TEXT("QWidget"), TEXT("MainParent"));
    if(hMSTSCWindow != NULL)
    {
        SetParent(this->winId(),hMSTSCWindow );

    }

Where am I going wrong?

Was it helpful?

Solution

As per MSDN any window which is not a top level window should not be made transparent below windows 8. otherwise behaviour might be unexpected like what I am experiencing one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top