Trying to Draw QRubberBand but QRubberBand not displayed properly
-
Qt version 5.8.0
Windows 7I am drawing a QRubberBand on a QLable, also coloring the QRubberBand Border as Yellow but the whole rectangle is filled with Yellow color.
I only want the QRubberBand borders to be yellow and not the inside of the QRubberBand
-
the following is the code i am using
dummyband = new QRubberBand(QRubberBand::Rectangle, this);
QPalette palette; //palette.setBrush(QPalette::Foreground, QBrush(color)); //palette.setBrush(QPalette::Base, QBrush(color)); palette.setBrush(QPalette::Highlight, QBrush(yellow)); dummyband->setPalette(palette); dummyband->setGeometry(QRect(topLeft, bottomRight)); dummyband->show();
-
Hi
The docs saysRectangle A QRubberBand can represent a rectangle. Some
styles will interpret this as a filled (often
semi-transparent) rectangle, or a rectangular
outline.It's also filled on windows 10 so I guess it's by design / also affected by the platform style.
It draws with QStyle::CE_RubberBand
so you could override with http://doc.qt.io/qt-5/qproxystyle.htmlclass MRubberStyle : public QProxyStyle { public: MRubberStyle() : QProxyStyle() {} ~MRubberStyle() {} virtual void drawControl(ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget = 0) const { switch(element) { case CE_RubberBand: // draw as u want return; default: QApplication::style()->drawControl(element, option, painter, widget); } } }; ... app.setStyle( new MRubberStyle );
-
You should not use setBrush, it will fill your rectangle with yellow color, Use setPen with yellow color, it will set the yellow border.
-
not getting setPen in QPalette
-
@Swapnil_Shelke ,
OK. try this,
rubberBand->setPalette(Qt::transparent); -
No not working ,
rubberBand->setPalette(Qt::transparent); removes the color from borders also..