如何将QFrame
的背景设置为半透明,以便我可以看到父窗口小部件(QWidget
)的背景。我尝试了这个,但背景仍然是黑色的:
QFrame {
margin: 10px;
background: #000000;
border: 1px solid black;
opacity: 0.5;
}
答案 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);
}