QWidget Semi-transparent Background Color
Jump to navigation
Jump to search
This code snippet shows how to make the background color of QWidget semi-transparent by overloading paintEvent().
Declare overload of paintEvent in .h file...
protected:
//overload from QWidget
void paintEvent(QPaintEvent* event);
Implement the overload of paintEvent in.cpp file...
void MyWidget::paintEvent(QPaintEvent* /*event*/) {
QColor backgroundColor = palette().light().color();
backgroundColor.setAlpha(200);
QPainter customPainter(this);
customPainter.fillRect(rect(),backgroundColor);
}