Thanks d_stranz, after some more attempts here's the working code.
#include <QPaintEvent>
#include <QPainter>
#include <QDebug>
{
Q_OBJECT
public:
explicit PaintWidget
(const QRect &paintArea,
QWidget *parent
=nullptr
) : QWidget(parent
), m_area
(paintArea
) {
setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_TransparentForMouseEvents);
}
~PaintWidget(){};
protected:
{
QPainter(this).
fillRect(m_area,
{255,
0,
0,
100});
}
private:
};
#include <QPaintEvent>
#include <QPainter>
#include <QDebug>
class PaintWidget : public QWidget
{
Q_OBJECT
public:
explicit PaintWidget(const QRect &paintArea, QWidget *parent=nullptr)
: QWidget(parent), m_area(paintArea)
{
setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_TransparentForMouseEvents);
}
~PaintWidget(){};
protected:
void paintEvent(QPaintEvent */*event*/) override
{
QPainter(this).fillRect(m_area, {255, 0, 0, 100});
}
private:
QRect m_area;
};
To copy to clipboard, switch view to plain text mode
And the calling function I resize the overlay widget to be the entire size of the treeview, but only paint the rectangle of interest.
PaintWidget *overlay = new PaintWidget(textRect, this);
overlay->resize(this->width(), this->height());
overlay->show();
PaintWidget *overlay = new PaintWidget(textRect, this);
overlay->resize(this->width(), this->height());
overlay->show();
To copy to clipboard, switch view to plain text mode
Bookmarks