Reputation: 61
My work Environment: Qt 5.8 MSVC2015 64bit, QT GraphicsView, QGraphicsObject, Windows 7 64 bit.
In my application I have added multiple QGraphicsitem, into a single graphic scene & into a single graphic view.
But I need to draw empty green color rectangle on top of QGraphicsitem image, as per mouse position. So I tried with below :
QRubberBand* _rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
_rubberBand->setGeometry(QRect(MousePos.x() -2, MousePos.y() - 2, MousePos.x() + 2, MousePos.y() + 2).normalized());
_rubberBand->setAutoFillBackground(false);
QPalette pal;
pal.setBrush(QPalette::Highlight, QBrush(Qt::green));
_rubberBand->setPalette(pal);
_rubberBand->show();
Issue with QRubberBand, it changes size dynamically, I want draw small rectangle, not flickery RubberBand.
QRubberBand Output:
Expected Output:
Upvotes: 0
Views: 1989
Reputation: 61
@m7913d, tons of thanks for your value added suggestion. I have Override QRubberBand class & set QRubberBand class setGeometry, setPen & it's color.
Here is final solution code :
class roiFrame : public QRubberBand
{
public:
roiFrame(Shape s, QWidget * p = 0):QRubberBand(s, p){}
~roiFrame(){}
protected:
void paintEvent(QPaintEvent *pe)
{
Q_UNUSED(pe);
QStyleOptionRubberBand opt;
QStylePainter painter(this);
opt.initFrom(this);
QRect rectangle(0,0,30, 15);
QColor color(Qt::green);
painter.setPen(color);
painter.drawRect(rectangle);
}
};
Caller code :
_rectFrame = new roiFrame(QRubberBand::Rectangle, this);
_rectFrame->setGeometry(QRect(thumbMousePos.x() -1, thumbMousePos.y() - 1, thumbMousePos.x() + 1, thumbMousePos.y() + 1).normalized());
_rectFrame->setAutoFillBackground(false);
_rectFrame->show();
Upvotes: 1