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();
}
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();
}
To copy to clipboard, switch view to plain text mode
Bookmarks