Transparent Window in qt4.5.1
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..................
Code:
TransparentWindow
::TransparentWindow(QWidget *parent
) : QDialog(parent, Qt
::FramelessWindowHint) {
bttn
->setGeometry
( QRect( 150,
100,
200,
25 ) );
connect(bttn, SIGNAL(clicked()), this, SLOT(setOpaque()));
setWindowTitle(tr("Transparent Window"));
//setFixedHeight(sizeHint().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
Re: Transparent Window in qt4.5.1
just try ..
use
void QPainter::setOpacity ( qreal opacity )
Code:
in paintEvent()
{
painter->setOpacity(opacity);
}
in void TransparentWindow::setOpaque()
{
opacity = 0.2;
update();
}
Re: Transparent Window in qt4.5.1
Have a look at Qt::WA_TranslucentBackgroundYou can use it to get a transparent window with non-transparent childs.
Re: Transparent Window in qt4.5.1
I have tried the option QPainter::setOpacity ( qreal opacity )
Still it didn't work.
Is there any other option.
Waiting for reply.
Raghvendra
Re: Transparent Window in qt4.5.1
setWindowOpacity() works only if you have composite extension enabled in X11. Here's an extract from Qt documentation of setWindowOpacity():
Quote:
Note that under X11 you need to have a composite manager running, and the X11 specific _NET_WM_WINDOW_OPACITY atom needs to be supported by the window manager you are using.
So, in my office PC with composite extension, setWindowOpacity() doesn't work but it works on my laptop as i have composite extension (Beryl 3D) installed.
Re: Transparent Window in qt4.5.1
Thnx for that Information.
Could you plz tell me how can i enable composite extension in X11. I am new to this concept.
Plz do reply...............
Regards
raghvendra
Re: Transparent Window in qt4.5.1
oops, sorry i missed this thread for long :(
u can just google for "how to enable composite extension in linux or X11"
Also, if you just want to show your desktop and make your window appear as transparent, you can use the grabWindow function to get the desktop background as a QPixmap and then you can just set your window background to that pixmap.