[Interest] How to have partially transparent widget on top that do not catch events
Frederik Christiani
frederik at vikingsoftware.com
Wed Jun 13 10:53:05 CEST 2018
Hi,
On 13-06-2018 09:26, Nicolas Krieger wrote:
> I would like to have a border in my widget, just like a QFrame. But a
> QFrame which border is over and not beside. I want to hide and show the
> border, but without layout re-sizing effects.
If I understand your problem correctly, you should be able to use a
QGraphicsEffect like this:
#include <QGraphicsEffect>
#include <QPainter>
class InsideBorderGraphicsEffect : public QGraphicsEffect
{
Q_OBJECT
public:
InsideBorderGraphicsEffect(QObject* parent = nullptr)
: QGraphicsEffect(parent)
{
}
protected:
void draw(QPainter* painter) override
{
QPoint offset;
const QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates,
&offset);
painter->drawPixmap(offset, pixmap);
painter->setPen(QPen(Qt::magenta, 10));
painter->drawRect(boundingRect());
}
};
Now it is just a matter of setting the effect on your widget with
setGraphicsEffect(new InsideBorderGraphicsEffect);
and clear it again with
setGraphicsEffect(nullptr);
--
Frederik Christiani
Viking Software
https://www.vikingsoftware.com/
More information about the Interest
mailing list