Custom QRubberBand with transparent background
Hi,
as already discussed here and here it should be possible to paint modify the appearance of the QRubberBand by making a subclass and overwriting the paintEvent. The rubberband should be displayed on QGraphicsView to select some items on a QGraphicsScene. I'm able to modify the frame color but the background of the rubber band rect remains completely transparent (white). Here is my implementation of the QRubberBand subclass
Code:
#include "SelectionFrame.h"
#include <QPaintEvent>
#include <QPainter>
#include <QDebug>
SelectionFrame
::SelectionFrame(Shape shape,
QWidget *parent
) :{
_border_color
= QColor(0,
83,
235);
_background_color
= QColor(51,
122,
255);
}
SelectionFrame::~SelectionFrame()
{
}
{
Q_UNUSED(event);
pen.setWidth(5);
pen.setStyle(Qt::DashLine);
painter.begin(this);
painter.setPen(pen);
painter.setOpacity(0.5);
painter.setBrush(brush);
painter.drawRect(event->rect());
painter.end();
}
As the painter's pen has been set to dashed, I think I can see, that there is an additional border painted on top of the dashed line with the correctly set transparency. The background is however not painter. Does anyone have a suggestion how this can be done right?
Re: Custom QRubberBand with transparent background
I thin I remained a little bit unclear about what I'm trying to achieve. The rubber bands background (the content of the selection rectangle) should be semi-transparent and have a special color. In my understanding the rubber bands default behavior, at least on my system, is to have a completely transparent content area with only the borders painted.