QWidget Semi-transparent Background Color

From Qt Wiki
Jump to: navigation, 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...

  //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();
 QPainter customPainter(this);

See Also

How to Change the Background Color of QWidget