Reputation: 93
I am using Qt Creator 4.5.2 (Qt 5.9.5, GCC 7.3.0 64-bit) and running on Ubuntu 18.04.
I have a QT MainWindow (a QWidget) which is QRectF(0,0,480,800). On the MainWindow, there is a QFrame which is QRectF(0,60,480,400). I would like to have the QFrame totally transparent. In other words, I would like to see the display on the Desktop of the PC behind the QFrame frame but not see the Desktop behind other parts of the QT MainWindow.
Is it possible? I have googled a lot and did not find a good solution.
I tried:
setStyleSheet("QFrame{border: None; background-color: transparent;}");
or
setStyleSheet("background-color: transparent; QFrame{border: None; background-color: transparent;}");
or
setStyleSheet("QFrame{border: None; background-color: rgba(0,0,0,100;}");
Neither of them work.
Upvotes: 1
Views: 1961
Reputation: 33
When you add QFrame to QMainWindow and set transparent background to QFrame, QMainWindow remains filled with some color. You need to set transparent style to QFrame:
frame->setStyleSheet("border: none; background: transparent;");
And than set attribute to QMainWindow:
mainWindow->setAttribute(Qt::WA_TranslucentBackground);
Upvotes: 1
Reputation: 165
This is working for me
widget->setStyleSheet("background-color: transparent;");
widget->setWindowFlags(Qt::FramelessWindowHint); //No windowing
widget->setAttribute(Qt::WA_TranslucentBackground); // No background
Upvotes: 3