Qt css背景半透明

时间:2015-02-11 08:52:15

标签: css qt qt-designer

如何将QFrame的背景设置为半透明,以便我可以看到父窗口小部件(QWidget)的背景。我尝试了这个,但背景仍然是黑色的:

QFrame {    
    margin: 10px;
    background: #000000;
    border: 1px solid black;
    opacity: 0.5;
}

1 个答案:

答案 0 :(得分:0)

请试试这个......

Widget::Widget(QWidget *parent) : QWidget(parent)
{
    setWindowFlags(Qt::Window | Qt::FramelessWindowHint);

    setAttribute(Qt::WA_NoSystemBackground);
    setAttribute(Qt::WA_TranslucentBackground);
    setAttribute(Qt::WA_PaintOnScreen);

    setAttribute(Qt::WA_TransparentForMouseEvents);
}

void Widget::paintEvent(QPaintEvent*)
{
    QPainter p(this);
    QString text = "Some foo goes here";
    QFontMetrics metrics(p.font());
    resize(metrics.size(0, text));
    p.drawText(rect(), Qt::AlignCenter, text);
}
相关问题