View Full Version : semi-transparent window with a visible line on it
nagpalma
26th April 2007, 15:59
Hi to all and good to be here!
I'm using Qt 4.2.3 on Windows XP and i'm trying to do a semi-transparent principal window drawing a simple line on it, changing the paintEvent of the Qwidget.
I don't want that line to be transparent. I used setWindowOpacity(0.0) but the line on it becames also tranparent.
How can i achieve my goal?
Any help would be appreciated.
Thanks,
nagpalma
marcel
26th April 2007, 16:01
In paintEvent(). where you draw the line, use painter->setOpacity( 1.0f ) before you draw the line and after you draw the line restore the original opacity.
Regards
nagpalma
26th April 2007, 16:44
Hi marcel,
it didn't solve the problem :(
I'm using the fowlling code:
#include <QtGui>
#include "transparent.h"
Transparent::Transparent(QWidget *parent)
: QWidget(parent, Qt::FramelessWindowHint)
{
setWindowTitle(tr("Transparent Window"));
setWindowOpacity(0.0);
}
//window.resize(400, 400);
//window.setFixedSize(500,500);
//window.showMaximized();
void Transparent::paintEvent(QPaintEvent *)
{
QPainter p(this);
p.setOpacity(1.0);
p.drawLine(0, 0, 50, 50); // drawing code
p.setOpacity(0.0);
}
QSize Transparent::sizeHint() const
{
return QSize(400, 400);
}
When i execute the application, the line doesn't appear
jpn
26th April 2007, 16:55
setWindowOpacity(0.0);
Just curious, what if you try:
setWindowOpacity(0.01);
I once tried to catch (drag and drop) events with a window having opacity of 0.0. No events were received until I changed the opacity to something non-zero. I think a window with opacity of 0.0 basically means a hidden window and it won't even receive paint events then.
Edit: Oh, and please use "[ code ]"-tags to make code snippets more readable.
nagpalma
26th April 2007, 17:28
thanks for your reply jpn, i changed to setWindowOpacity(0.01) but i got the same result
jpn
26th April 2007, 17:45
I have my doubts that one could really turn QPainter opaque on a window that has been made transparent at system level. I'm not in Windows right now so I can't test (and neither do I have an extension manager running on X11). But what about testing for example with setWindowOpacity(0.5) if QPainter::setOpacity() really has any effect then?
nagpalma
26th April 2007, 18:25
I tried setWindowOpacity(0.5) and i don't think QPainter::setOpacity() has any effect at all
nagpalma
27th April 2007, 10:58
Hi,
I confirm, QPainter::setOpacity() had no effect after use setWindowOpacity().
Any suggestions?
Thanks,
nagpalma
vermarajeev
27th April 2007, 12:00
Hi,
I confirm, QPainter::setOpacity() had no effect after use setWindowOpacity().
Any suggestions?
Thanks,
nagpalma
This code works for me on windows Xp
Transparent::Transparent(QWidget *parent)
: QWidget(parent) {
setWindowTitle(tr("Transparent Window"));
setWindowOpacity(0.2f);
}
void Transparent::paintEvent(QPaintEvent *) {
QPainter p(this);
p.setPen( QPen( Qt::red ) );
p.setOpacity(1.0f);
p.drawLine(0, 0, 50, 50);
p.setOpacity(0.0f);
}
int main(int argc, char *argv[]){
QApplication a(argc, argv);
Transparent w;
w.show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
jpn
27th April 2007, 12:15
This code works for me on windows Xp
Make it
p.setPen( QPen( Qt::red, 5 ) );
and you'll notice that the line is transparent too.
nagpalma
27th April 2007, 13:15
I tried your code Vermarajeev but like jpn said, the line remains transparent :(
nagpalma
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.