Layouts don't have paintEvent
member so you can't reimplement it. I'm surprised you managed to get some effect from this action.
- Add new
QWidget
(let's call it wrapper) into your form and add yourQVBoxLayout
into this widget. - Create another widget (overlay) and add it to the wrapper using
setParent()
, not adding it into layout. - Reimplement overlay's paintEvent or add some other widgets to the overlay.
Simple example (tested):
class MyWidget : public QWidget {
public:
void paintEvent(QPaintEvent *e) {
QWidget::paintEvent(e);
QPainter p(this);
p.fillRect(4, 4, 30, 30, QBrush(Qt::red));
}
};
QWidget* wrapper = new QWidget();
QVBoxLayout* layout = new QVBoxLayout(wrapper);
layout->addWidget(new QLabel("test1"));
layout->addWidget(new QLabel("test2"));
MyWidget* overlay = new MyWidget();
overlay->setParent(wrapper);
wrapper->show();