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();
}
Bookmarks