PDA

View Full Version : How to make a mainwindow as earlier after making it transparent



Niamita
9th January 2012, 08:06
Hi all

I want to make my background transparent when clicked a button and after clicking on another button i want to make background as it was earlier. I try


this->setStyleSheet("background:transparent");
this->setAttribute(Qt::WA_TranslucentBackground, true);
this->setWindowFlags(Qt::FramelessWindowHint);
and

this->setStyleSheet("background:transparent");
this->setAttribute(Qt::WA_TranslucentBackground, false);
this->setWindowFlags(Qt::FramelessWindowHint);
but not getting desired result.
What i am doing here.
Waiting for yours response.

Lykurg
9th January 2012, 08:50
Try to set an empty style sheet or simply use QPalette and set the default background or save the properties before you set the transparent background.

Niamita
9th January 2012, 18:21
Thanks for reply.
Can you give some example code.

Lykurg
9th January 2012, 18:53
void MainWindow::on_a_clicked()
{
setAttribute(Qt::WA_TranslucentBackground, true);
setStyleSheet("background:transparent;");
}

void MainWindow::on_b_clicked()
{
setAttribute(Qt::WA_TranslucentBackground, false);
setStyleSheet("background:red;");
}