ipx
8th April 2013, 09:09
I use QT4.8 in embeded linux arm platform
the below layer of /dev/fb0 is video,So I want the whole QT program is transparent!
when I update the OSD(developed by QT) every second with different content, I found the new content was stacks with the old.
the old can't be erased auto even by hand if the background or the fill color is transparent!
And hide() and show() doesn't work in the same time,It will show always except not update the content when hide().
but if I set background opaque, it will ok!
How can I make the old content transparecy or erase them.
thanks, I really want your help!!!
below is the code:
Window::Window(): QWidget()
{
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground,true);
setAttribute(Qt::WA_NoSystemBackground);
setFixedSize(100, 100);
textPen = QPen(Qt::red);
textFont.setPixelSize(40);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(animate()));
timer->start(1000);}
void Window::animate()
{
strTime = (QTime::currentTime()).toString(tr("hh:mm:ss"));
update();}
void Window::paintEvent(QPaintEvent *event)
{
QPainter painter;
painter.begin(this);
painter.setBackgroundMode(Qt::TransparentMode);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(textPen);
painter.setFont(textFont);
painter.fillRect(event->rect(), QColor(0,0,0,0));
painter.drawText(QRect(0, 0, 100, 100), Qt::AlignCenter, strTime);
painter.end();
}
int main(int argc, char *argv[])
{
QWSServer::setBackground(QBrush(QColor(0,0,0,0)));
QApplication app(argc, argv);
Window window;
window.show();
return app.exec();}
the below layer of /dev/fb0 is video,So I want the whole QT program is transparent!
when I update the OSD(developed by QT) every second with different content, I found the new content was stacks with the old.
the old can't be erased auto even by hand if the background or the fill color is transparent!
And hide() and show() doesn't work in the same time,It will show always except not update the content when hide().
but if I set background opaque, it will ok!
How can I make the old content transparecy or erase them.
thanks, I really want your help!!!
below is the code:
Window::Window(): QWidget()
{
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground,true);
setAttribute(Qt::WA_NoSystemBackground);
setFixedSize(100, 100);
textPen = QPen(Qt::red);
textFont.setPixelSize(40);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(animate()));
timer->start(1000);}
void Window::animate()
{
strTime = (QTime::currentTime()).toString(tr("hh:mm:ss"));
update();}
void Window::paintEvent(QPaintEvent *event)
{
QPainter painter;
painter.begin(this);
painter.setBackgroundMode(Qt::TransparentMode);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(textPen);
painter.setFont(textFont);
painter.fillRect(event->rect(), QColor(0,0,0,0));
painter.drawText(QRect(0, 0, 100, 100), Qt::AlignCenter, strTime);
painter.end();
}
int main(int argc, char *argv[])
{
QWSServer::setBackground(QBrush(QColor(0,0,0,0)));
QApplication app(argc, argv);
Window window;
window.show();
return app.exec();}