raghvendramisra
16th June 2009, 07:08
HI all,
i have a requirement to display a transparent window such that when it is displayed i should be able to see my Desktop.
I have used setWindowOpacity() for this but it dosen't work.
Plz give me suggestion to correct my program.
Below is a small piece of code..................
TransparentWindow::TransparentWindow(QWidget *parent)
: QDialog(parent, Qt::FramelessWindowHint)
{
QPushButton *bttn = new QPushButton("Test",this);
bttn->setGeometry( QRect( 150, 100,200, 25 ) );
connect(bttn, SIGNAL(clicked()), this, SLOT(setOpaque()));
setWindowTitle(tr("Transparent Window"));
//setFixedHeight(sizeHint().height());
}
void TransparentWindow::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QLinearGradient grad(0, 0, rect().width(), rect().height());
painter.fillRect(0, 0, rect().width(), rect().height(), grad);
}
void TransparentWindow::setOpaque()
{
setAttribute(Qt::WA_NoSystemBackground, true);
setAttribute(Qt::WA_TranslucentBackground, true);
setWindowOpacity(0.1);
repaint();
}
Regards
Raghav
i have a requirement to display a transparent window such that when it is displayed i should be able to see my Desktop.
I have used setWindowOpacity() for this but it dosen't work.
Plz give me suggestion to correct my program.
Below is a small piece of code..................
TransparentWindow::TransparentWindow(QWidget *parent)
: QDialog(parent, Qt::FramelessWindowHint)
{
QPushButton *bttn = new QPushButton("Test",this);
bttn->setGeometry( QRect( 150, 100,200, 25 ) );
connect(bttn, SIGNAL(clicked()), this, SLOT(setOpaque()));
setWindowTitle(tr("Transparent Window"));
//setFixedHeight(sizeHint().height());
}
void TransparentWindow::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QLinearGradient grad(0, 0, rect().width(), rect().height());
painter.fillRect(0, 0, rect().width(), rect().height(), grad);
}
void TransparentWindow::setOpaque()
{
setAttribute(Qt::WA_NoSystemBackground, true);
setAttribute(Qt::WA_TranslucentBackground, true);
setWindowOpacity(0.1);
repaint();
}
Regards
Raghav